8000 bug #25696 [FrameworkBundle] Fix using "annotations.cached_reader" in… · symfony/symfony@7085569 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7085569

Browse files
committed
bug #25696 [FrameworkBundle] Fix using "annotations.cached_reader" in after-removing passes (nicolas-grekas)
This PR was merged into the 3.3 branch. Discussion ---------- [FrameworkBundle] Fix using "annotations.cached_reader" in after-removing passes | Q | A | ------------- | --- | Branch? | 3.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #25695 | License | MIT | Doc PR | - When `annotation_reader` is instantiated in an after-removing pass, it gets the real cache provider, instead of the dummy one that should be provided during compilation of the container. This situation is found in e.g. `JMS\AopBundle\DependencyInjection\Compiler\PointcutMatchingPass`. A workaround before next release could be to "get" the `annotation_reader` service somewhere before (like in a regular compiler pass of your own.) Commits ------- f66f9a7 [FrameworkBundle] Fix using "annotations.cached_reader" in after-removing passes
2 parents 6108a21 + f66f9a7 commit 7085569

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddAnnotationsCachedReaderPass.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
1515
use Symfony\Component\DependencyInjection\ContainerBuilder;
16-
use Symfony\Component\DependencyInjection\Reference;
1716

1817
/**
1918
* @internal
@@ -29,14 +28,14 @@ public function process(ContainerBuilder $container)
2928
// "annotation_reader" at build time don't get any cache
3029
if ($container->hasDefinition('annotations.cached_reader')) {
3130
$reader = $container->getDefinition('annotations.cached_reader');
32-
$tags = $reader->getTags();
31+
$properties = $reader->getProperties();
3332

34-
if (isset($tags['annotations.cached_reader'][0]['provider'])) {
35-
if ($container->hasAlias($provider = $tags['annotations.cached_reader'][0]['provider'])) {
36-
$provider = (string) $container->getAlias($provider);
37-
}
33+
if (isset($properties['cacheProviderBackup'])) {
34+
$provider = $properties['cacheProviderBackup']->getValues()[0];
35+
unset($properties['cacheProviderBackup']);
36+
$reader->setProperties($properties);
3837
$container->set('annotations.cached_reader', null);
39-
$container->setDefinition('annotations.cached_reader', $reader->replaceArgument(1, new Reference($provider)));
38+
$container->setDefinition('annotations.cached_reader', $reader->replaceArgument(1, $provider));
4039
}
4140
}
4241
}

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use Symfony\Component\Console\Application;
2626
use Symfony\Component\Console\Command\Command;
2727
use Symfony\Component\DependencyInjection\Alias;
28+
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
2829
use Symfony\Component\DependencyInjection\ChildDefinition;
2930
use Symfony\Component\DependencyInjection\ContainerBuilder;
3031
use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -1131,7 +1132,8 @@ private function registerAnnotationsConfiguration(array $config, ContainerBuilde
11311132
$container
11321133
->getDefinition('annotations.cached_reader')
11331134
->replaceArgument(2, $config['debug'])
1134-
->addTag('annotations.cached_reader', array('provider' => $cacheService))
1135+
// temporary property to lazy-reference the cache provider without using it until AddAnnotationsCachedReaderPass runs
1136+
->setProperty('cacheProviderBackup', new ServiceClosureArgument(new Reference($cacheService)))
11351137
;
11361138
$container->setAlias('annotation_reader', 'annotations.cached_reader');
11371139
$container->setAlias(Reader::class, new Alias('annotations.cached_reader', false));

src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function build(ContainerBuilder $container)
9191
$container->addCompilerPass(new RegisterListenersPass(), PassConfig::TYPE_BEFORE_REMOVING);
9292
$container->addCompilerPass(new TemplatingPass());
9393
$this->addCompilerPassIfExists($container, AddConstraintValidatorsPass::class, PassConfig::TYPE_BEFORE_REMOVING);
94-
$container->addCompilerPass(new AddAnnotationsCachedReaderPass(), PassConfig::TYPE_BEFORE_REMOVING);
94+
$container->addCompilerPass(new AddAnnotationsCachedReaderPass(), PassConfig::TYPE_AFTER_REMOVING, -255);
9595
$this->addCompilerPassIfExists($container, AddValidatorInitializersPass::class);
9696
$this->addCompilerPassIfExists($container, AddConsoleCommandPass::class);
9797
$container->addCompilerPass(new TranslatorPass());

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/TestBundle.php

Lines changed: 2 additions & 1 deletion
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle;
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
1313

1414
use Symfony\Component\HttpKernel\Bundle\Bundle;
15+
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
1516
use Symfony\Component\DependencyInjection\ContainerBuilder;
1617
use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\DependencyInjection\AnnotationReaderPass;
1718
use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\DependencyInjection\Config\CustomConfig;
@@ -27,6 +28,6 @@ public function build(ContainerBuilder $container)
2728

2829
$extension->setCustomConfig(new CustomConfig());
2930

30-
$container->addCompilerPass(new AnnotationReaderPass());
31+
$container->addCompilerPass(new AnnotationReaderPass(), PassConfig::TYPE_AFTER_REMOVING);
3132
}
3233
}

0 commit comments

Comments
 (0)
0