Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[DI][FrameworkBundle] Remove "whitelist" occurrences #37376

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
class UnusedTagsPass implements CompilerPassInterface
{
private $whitelist = [
private $knownTags = [
'annotations.cached_reader',
'auto_alias',
'cache.pool',
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@

$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);
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,21 @@ public function testProcess()
$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]))));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1176,9 +1176,9 @@ private function createService(Definition $definition, array &$inlineServices, $
$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);
}
}
Expand Down