Skip to content

[FrameworkBundle] Fix using "annotations.cached_reader" in after-removing passes #25696

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
Jan 8, 2018
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 @@ -13,7 +13,6 @@

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

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

if (isset($tags['annotations.cached_reader'][0]['provider'])) {
if ($container->hasAlias($provider = $tags['annotations.cached_reader'][0]['provider'])) {
$provider = (string) $container->getAlias($provider);
}
if (isset($properties['cacheProviderBackup'])) {
$provider = $properties['cacheProviderBackup']->getValues()[0];
unset($properties['cacheProviderBackup']);
$reader->setProperties($properties);
$container->set('annotations.cached_reader', null);
$container->setDefinition('annotations.cached_reader', $reader->replaceArgument(1, new Reference($provider)));
$container->setDefinition('annotations.cached_reader', $reader->replaceArgument(1, $provider));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
Expand Down Expand Up @@ -1131,7 +1132,8 @@ private function registerAnnotationsConfiguration(array $config, ContainerBuilde
$container
->getDefinition('annotations.cached_reader')
->replaceArgument(2, $config['debug'])
->addTag('annotations.cached_reader', array('provider' => $cacheService))
// temporary property to lazy-reference the cache provider without using it until AddAnnotationsCachedReaderPass runs
->setProperty('cacheProviderBackup', new ServiceClosureArgument(new Reference($cacheService)))
;
$container->setAlias('annotation_reader', 'annotations.cached_reader');
$container->setAlias(Reader::class, new Alias('annotations.cached_reader', false));
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function build(ContainerBuilder $container)
$container->addCompilerPass(new RegisterListenersPass(), PassConfig::TYPE_BEFORE_REMOVING);
$container->addCompilerPass(new TemplatingPass());
$this->addCompilerPassIfExists($container, AddConstraintValidatorsPass::class, PassConfig::TYPE_BEFORE_REMOVING);
$container->addCompilerPass(new AddAnnotationsCachedReaderPass(), PassConfig::TYPE_BEFORE_REMOVING);
$container->addCompilerPass(new AddAnnotationsCachedReaderPass(), PassConfig::TYPE_AFTER_REMOVING, -255);
$this->addCompilerPassIfExists($container, AddValidatorInitializersPass::class);
$this->addCompilerPassIfExists($container, AddConsoleCommandPass::class);
$container->addCompilerPass(new TranslatorPass());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle;

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

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

$container->addCompilerPass(new AnnotationReaderPass());
$container->addCompilerPass(new AnnotationReaderPass(), PassConfig::TYPE_AFTER_REMOVING);
}
}