-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
minor #35833 [FrameworkBundle] Add missing items in the unused tag pa…
…ss whitelist (fabpot) This PR was merged into the 5.1-dev branch. Discussion ---------- [FrameworkBundle] Add missing items in the unused tag pass whitelist | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | n/a <!-- prefix each issue number with "Fix #", if any --> | License | MIT | Doc PR | n/a We have some missing tags in the whitelist. I've added a script that adds the missing ones, and added a test to avoid forgetting about updating the whitelist. Commits ------- d1bcc0f [FrameworkBundle] Add a script that checks for missing items in the unused tag whitelist
- Loading branch information
1 parent
d7250ef
commit b515bc9
Showing
4 changed files
with
122 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/Symfony/Bundle/FrameworkBundle/Resources/bin/check-unused-tags-whitelist.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
require dirname(__DIR__, 6).'/vendor/autoload.php'; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler\UnusedTagsPassUtils; | ||
|
||
$target = dirname(__DIR__, 2).'/DependencyInjection/Compiler/UnusedTagsPass.php'; | ||
$contents = file_get_contents($target); | ||
$contents = preg_replace('{private \$whitelist = \[(.+?)\];}sm', "private \$whitelist = [\n '".implode("',\n '", UnusedTagsPassUtils::getDefinedTags())."',\n ];", $contents); | ||
file_put_contents($target, $contents); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/UnusedTagsPassUtils.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler; | ||
|
||
use Symfony\Component\Finder\Finder; | ||
|
||
class UnusedTagsPassUtils | ||
{ | ||
public static function getDefinedTags() | ||
{ | ||
$tags = [ | ||
'proxy' => true, | ||
]; | ||
|
||
// get all tags used in XML configs | ||
$files = Finder::create()->files()->name('*.xml')->path('Resources')->notPath('Tests')->in(\dirname(__DIR__, 5)); | ||
foreach ($files as $file) { | ||
$contents = file_get_contents($file); | ||
if (preg_match_all('{<tag name="([^"]+)"}', $contents, $matches)) { | ||
foreach ($matches[1] as $match) { | ||
$tags[$match] = true; | ||
} | ||
} | ||
if (preg_match_all('{<argument type="tagged_.+?" tag="([^"]+)"}', $contents, $matches)) { | ||
foreach ($matches[1] as $match) { | ||
$tags[$match] = true; | ||
} | ||
} | ||
} | ||
|
||
// get all tags used in findTaggedServiceIds calls() | ||
$files = Finder::create()->files()->name('*.php')->path('DependencyInjection')->notPath('Tests')->in(\dirname(__DIR__, 5)); | ||
foreach ($files as $file) { | ||
$contents = file_get_contents($file); | ||
if (preg_match_all('{findTaggedServiceIds\(\'([^\']+)\'}', $contents, $matches)) { | ||
foreach ($matches[1] as $match) { | ||
if ('my.tag' === $match) { | ||
continue; | ||
} | ||
$tags[$match] = true; | ||
} | ||
} | ||
if (preg_match_all('{findTaggedServiceIds\(\$this->([^,\)]+)}', $contents, $matches)) { | ||
foreach ($matches[1] as $var) { | ||
if (preg_match_all('{\$'.$var.' = \'([^\']+)\'}', $contents, $matches)) { | ||
foreach ($matches[1] as $match) { | ||
$tags[$match] = true; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
$tags = array_keys($tags); | ||
sort($tags); | ||
|
||
return $tags; | ||
} | ||
} |