[DI][FrameworkBundle] Remove whitelist occurrences
This commit is contained in:
parent
e707967ea8
commit
12ab96ec9b
@ -21,7 +21,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
*/
|
||||
class UnusedTagsPass implements CompilerPassInterface
|
||||
{
|
||||
private $whitelist = [
|
||||
private $knownTags = [
|
||||
'annotations.cached_reader',
|
||||
'auto_alias',
|
||||
'cache.pool',
|
||||
@ -70,11 +70,11 @@ class UnusedTagsPass implements CompilerPassInterface
|
||||
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
$tags = array_unique(array_merge($container->findTags(), $this->whitelist));
|
||||
$tags = array_unique(array_merge($container->findTags(), $this->knownTags));
|
||||
|
||||
foreach ($container->findUnusedTags() as $tag) {
|
||||
// skip whitelisted tags
|
||||
if (\in_array($tag, $this->whitelist)) {
|
||||
// skip known tags
|
||||
if (\in_array($tag, $this->knownTags)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -15,5 +15,5 @@ use Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler\UnusedTags
|
||||
|
||||
$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);
|
||||
$contents = preg_replace('{private \$knownTags = \[(.+?)\];}sm', "private \$knownTags = [\n '".implode("',\n '", UnusedTagsPassUtils::getDefinedTags())."',\n ];", $contents);
|
||||
file_put_contents($target, $contents);
|
@ -35,21 +35,21 @@ class UnusedTagsPassTest extends TestCase
|
||||
$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());
|
||||
}
|
||||
|
||||
public function testMissingWhitelistTags()
|
||||
public function testMissingKnownTags()
|
||||
{
|
||||
if (\dirname((new \ReflectionClass(ContainerBuilder::class))->getFileName(), 3) !== \dirname(__DIR__, 5)) {
|
||||
$this->markTestSkipped('Tests are not run from the root symfony/symfony metapackage.');
|
||||
}
|
||||
|
||||
$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.');
|
||||
$this->assertSame(UnusedTagsPassUtils::getDefinedTags(), $this->getKnownTags(), 'The src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/UnusedTagsPass.php file must be updated; run src/Symfony/Bundle/FrameworkBundle/Resources/bin/check-unused-known-tags.php.');
|
||||
}
|
||||
|
||||
private function getWhitelistTags()
|
||||
private function getKnownTags()
|
||||
{
|
||||
// get tags in UnusedTagsPass
|
||||
$target = \dirname(__DIR__, 3).'/DependencyInjection/Compiler/UnusedTagsPass.php';
|
||||
$contents = file_get_contents($target);
|
||||
preg_match('{private \$whitelist = \[(.+?)\];}sm', $contents, $matches);
|
||||
preg_match('{private \$knownTags = \[(.+?)\];}sm', $contents, $matches);
|
||||
$tags = array_values(array_filter(array_map(function ($str) {
|
||||
return trim(preg_replace('{^ +\'(.+)\',}', '$1', $str));
|
||||
}, explode("\n", $matches[1]))));
|
||||
|
@ -1176,9 +1176,9 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
||||
$service = null === $r->getConstructor() ? $r->newInstance() : $r->newInstanceArgs($arguments);
|
||||
// don't trigger deprecations for internal uses
|
||||
// @deprecated since version 3.3, to be removed in 4.0 along with the deprecated class
|
||||
$deprecationWhitelist = ['event_dispatcher' => ContainerAwareEventDispatcher::class];
|
||||
$deprecationAllowlist = ['event_dispatcher' => ContainerAwareEventDispatcher::class];
|
||||
|
||||
if (!$definition->isDeprecated() && 0 < strpos($r->getDocComment(), "\n * @deprecated ") && (!isset($deprecationWhitelist[$id]) || $deprecationWhitelist[$id] !== $class)) {
|
||||
if (!$definition->isDeprecated() && 0 < strpos($r->getDocComment(), "\n * @deprecated ") && (!isset($deprecationAllowlist[$id]) || $deprecationAllowlist[$id] !== $class)) {
|
||||
@trigger_error(sprintf('The "%s" service relies on the deprecated "%s" class. It should either be deprecated or its implementation upgraded.', $id, $r->name), E_USER_DEPRECATED);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user