Skip to content

Commit fdeeee1

Browse files
Merge branch '3.4' into 4.4
* 3.4: minor #35833 [FrameworkBundle] Add missing items in the unused tag pass whitelist (fabpot) [Validator] Add missing translations
2 parents 6f9aa9f + 66440d8 commit fdeeee1

File tree

4 files changed

+128
-3
lines changed

4 files changed

+128
-3
lines changed

DependencyInjection/Compiler/UnusedTagsPass.php

+18-3
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,20 @@ class UnusedTagsPass implements CompilerPassInterface
2323
{
2424
private $whitelist = [
2525
'annotations.cached_reader',
26+
'auto_alias',
27+
'cache.pool',
2628
'cache.pool.clearer',
29+
'config_cache.resource_checker',
2730
'console.command',
31+
'container.env_var_loader',
32+
'container.env_var_processor',
2833
'container.hot_path',
2934
'container.reversible',
3035
'container.service_locator',
36+
'container.service_locator_context',
3137
'container.service_subscriber',
38+
'controller.argument_value_resolver',
3239
'controller.service_arguments',
33-
'config_cache.resource_checker',
3440
'data_collector',
3541
'form.type',
3642
'form.type_extension',
@@ -42,11 +48,18 @@ class UnusedTagsPass implements CompilerPassInterface
4248
'kernel.event_subscriber',
4349
'kernel.fragment_renderer',
4450
'kernel.locale_aware',
51+
'kernel.reset',
52+
'mailer.transport_factory',
4553
'messenger.bus',
46-
'messenger.receiver',
4754
'messenger.message_handler',
55+
'messenger.receiver',
56+
'messenger.transport_factory',
4857
'mime.mime_type_guesser',
4958
'monolog.logger',
59+
'property_info.access_extractor',
60+
'property_info.initializable_extractor',
61+
'property_info.list_extractor',
62+
'property_info.type_extractor',
5063
'proxy',
5164
'routing.expression_language_provider',
5265
'routing.loader',
@@ -62,9 +75,11 @@ class UnusedTagsPass implements CompilerPassInterface
6275
'translation.loader',
6376
'twig.extension',
6477
'twig.loader',
78+
'twig.runtime',
79+
'validator.auto_mapper',
6580
'validator.constraint_validator',
6681
'validator.initializer',
67-
'validator.auto_mapper',
82+
'workflow.definition',
6883
];
6984

7085
public function process(ContainerBuilder $container)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
require dirname(__DIR__, 6).'/vendor/autoload.php';
13+
14+
use Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler\UnusedTagsPassUtils;
15+
16+
$target = dirname(__DIR__, 2).'/DependencyInjection/Compiler/UnusedTagsPass.php';
17+
$contents = file_get_contents($target);
18+
$contents = preg_replace('{private \$whitelist = \[(.+?)\];}sm', "private \$whitelist = [\n '".implode("',\n '", UnusedTagsPassUtils::getDefinedTags())."',\n ];", $contents);
19+
file_put_contents($target, $contents);

Tests/DependencyInjection/Compiler/UnusedTagsPassTest.php

+23
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,27 @@ public function testProcess()
3131

3232
$this->assertSame([sprintf('%s: Tag "kenrel.event_subscriber" was defined on service(s) "foo", "bar", but was never used. Did you mean "kernel.event_subscriber"?', UnusedTagsPass::class)], $container->getCompiler()->getLog());
3333
}
34+
35+
public function testMissingWhitelistTags()
36+
{
37+
if (\dirname((new \ReflectionClass(ContainerBuilder::class))->getFileName(), 3) !== \dirname(__DIR__, 5)) {
38+
$this->markTestSkipped('Tests are not run from the root symfony/symfony metapackage.');
39+
}
40+
41+
$this->assertSame(UnusedTagsPassUtils::getDefinedTags(), $this->getWhitelistTags(), 'The src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/UnusedTagsPass.php file must be updated; run src/Symfony/Bundle/FrameworkBundle/Resources/bin/check-unused-tags-whitelist.php.');
42+
}
43+
44+
private function getWhitelistTags()
45+
{
46+
// get tags in UnusedTagsPass
47+
$target = \dirname(__DIR__, 3).'/DependencyInjection/Compiler/UnusedTagsPass.php';
48+
$contents = file_get_contents($target);
49+
preg_match('{private \$whitelist = \[(.+?)\];}sm', $contents, $matches);
50+
$tags = array_values(array_filter(array_map(function ($str) {
51+
return trim(preg_replace('{^ +\'(.+)\',}', '$1', $str));
52+
}, explode("\n", $matches[1]))));
53+
sort($tags);
54+
55+
return $tags;
56+
}
3457
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
13+
14+
use Symfony\Component\Finder\Finder;
15+
16+
class UnusedTagsPassUtils
17+
{
18+
public static function getDefinedTags()
19+
{
20+
$tags = [
21+
'proxy' => true,
22+
];
23+
24+
// get all tags used in XML configs
25+
$files = Finder::create()->files()->name('*.xml')->path('Resources')->notPath('Tests')->in(\dirname(__DIR__, 5));
26+
foreach ($files as $file) {
27+
$contents = file_get_contents($file);
28+
if (preg_match_all('{<tag name="([^"]+)"}', $contents, $matches)) {
29+
foreach ($matches[1] as $match) {
30+
$tags[$match] = true;
31+
}
32+
}
33+
if (preg_match_all('{<argument type="tagged_.+?" tag="([^"]+)"}', $contents, $matches)) {
34+
foreach ($matches[1] as $match) {
35+
$tags[$match] = true;
36+
}
37+
}
38+
}
39+
40+
// get all tags used in findTaggedServiceIds calls()
41+
$files = Finder::create()->files()->name('*.php')->path('DependencyInjection')->notPath('Tests')->in(\dirname(__DIR__, 5));
42+
foreach ($files as $file) {
43+
$contents = file_get_contents($file);
44+
if (preg_match_all('{findTaggedServiceIds\(\'([^\']+)\'}', $contents, $matches)) {
45+
foreach ($matches[1] as $match) {
46+
if ('my.tag' === $match) {
47+
continue;
48+
}
49+
$tags[$match] = true;
50+
}
51+
}
52+
if (preg_match_all('{findTaggedServiceIds\(\$this->([^,\)]+)}', $contents, $matches)) {
53+
foreach ($matches[1] as $var) {
54+
if (preg_match_all('{\$'.$var.' = \'([^\']+)\'}', $contents, $matches)) {
55+
foreach ($matches[1] as $match) {
56+
$tags[$match] = true;
57+
}
58+
}
59+
}
60+
}
61+
}
62+
63+
$tags = array_keys($tags);
64+
sort($tags);
65+
66+
return $tags;
67+
}
68+
}

0 commit comments

Comments
 (0)