Skip to content

Commit 2d7ad46

Browse files
Merge branch '3.4' into 4.0
* 3.4: [Bridge/Twig] fix composer.json bug #26086 [FrameworkBundle] Fix using annotation_reader in compiler pass to inject configured cache provider [WebProfilerBundle] Fix anchor CSS [HttpKernel] Send new session cookie from AbstractTestSessionListener after session invalidation [WebProfilerBundle] Tweak default route name updated StopwatchEvent phpdoc due to the additional of optional float precision introduced in 0db8d7fb6a5396f84f2907e5e595c114982772ff Retro-fit proxy code to make it deterministic for older proxy manager implementations Yaml parser regression with comments and non-strings Fix undiscoverablility of SymfonyTestsListenerForV7 Fixed broken tests [TwigBridge] Apply some changes to support Bootstrap4-stable
2 parents ff24bac + 7065853 commit 2d7ad46

File tree

4 files changed

+32
-9
lines changed

4 files changed

+32
-9
lines changed

DependencyInjection/Compiler/AddAnnotationsCachedReaderPass.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ public function process(ContainerBuilder $container)
2626
{
2727
// "annotations.cached_reader" is wired late so that any passes using
2828
// "annotation_reader" at build time don't get any cache
29-
if ($container->hasDefinition('annotations.cached_reader')) {
30-
$reader = $container->getDefinition('annotations.cached_reader');
29+
foreach ($container->findTaggedServiceIds('annotations.cached_reader') as $id => $tags) {
30+
$reader = $container->getDefinition($id);
3131
$properties = $reader->getProperties();
3232

3333
if (isset($properties['cacheProviderBackup'])) {
3434
$provider = $properties['cacheProviderBackup']->getValues()[0];
3535
unset($properties['cacheProviderBackup']);
3636
$reader->setProperties($properties);
37-
$container->set('annotations.cached_reader', null);
38-
$container->setDefinition('annotations.cached_reader', $reader->replaceArgument(1, $provider));
37+
$container->set($id, null);
38+
$container->setDefinition($id, $reader->replaceArgument(1, $provider));
3939
}
4040
}
4141
}

DependencyInjection/Compiler/UnusedTagsPass.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
class UnusedTagsPass implements CompilerPassInterface
2323
{
2424
private $whitelist = array(
25+
'annotations.cached_reader',
2526
'cache.pool.clearer',
2627
'console.command',
2728
'container.hot_path',

DependencyInjection/FrameworkExtension.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,9 @@ private function registerAnnotationsConfiguration(array $config, ContainerBuilde
11161116
->replaceArgument(2, $config['debug'])
11171117
// temporary property to lazy-reference the cache provider without using it until AddAnnotationsCachedReaderPass runs
11181118
->setProperty('cacheProviderBackup', new ServiceClosureArgument(new Reference($cacheService)))
1119+
->addTag('annotations.cached_reader')
11191120
;
1121+
11201122
$container->setAlias('annotation_reader', 'annotations.cached_reader')->setPrivate(true);
11211123
$container->setAlias(Reader::class, new Alias('annotations.cached_reader', false));
11221124
} else {

Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use Symfony\Component\Cache\Adapter\ProxyAdapter;
2626
use Symfony\Component\Cache\Adapter\RedisAdapter;
2727
use Symfony\Component\DependencyInjection\ChildDefinition;
28+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
2829
use Symfony\Component\DependencyInjection\ContainerBuilder;
2930
use Symfony\Component\DependencyInjection\Definition;
3031
use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
@@ -582,10 +583,12 @@ public function testValidationService()
582583

583584
public function testAnnotations()
584585
{
585-
$container = $this->createContainerFromFile('full');
586+
$container = $this->createContainerFromFile('full', array(), true, false);
587+
$container->addCompilerPass(new TestAnnotationsPass());
588+
$container->compile();
586589

587590
$this->assertEquals($container->getParameter('kernel.cache_dir').'/annotations', $container->getDefinition('annotations.filesystem_cache')->getArgument(0));
588-
$this->assertSame('annotations.filesystem_cache', (string) $container->getDefinition('annotations.cached_reader')->getArgument(1));
591+
$this->assertSame('annotations.filesystem_cache', (string) $container->getDefinition('annotation_reader')->getArgument(1));
589592
}
590593

591594
public function testFileLinkFormat()
@@ -1029,10 +1032,10 @@ protected function createContainer(array $data = array())
10291032
), $data)));
10301033
}
10311034

1032-
protected function createContainerFromFile($file, $data = array(), $resetCompilerPasses = true)
1035+
protected function createContainerFromFile($file, $data = array(), $resetCompilerPasses = true, $compile = true)
10331036
{
10341037
$cacheKey = md5(get_class($this).$file.serialize($data));
1035-
if (isset(self::$containerCache[$cacheKey])) {
1038+
if ($compile && isset(self::$containerCache[$cacheKey])) {
10361039
return self::$containerCache[$cacheKey];
10371040
}
10381041
$container = $this->createContainer($data);
@@ -1043,7 +1046,12 @@ protected function createContainerFromFile($file, $data = array(), $resetCompile
10431046
$container->getCompilerPassConfig()->setOptimizationPasses(array());
10441047
$container->getCompilerPassConfig()->setRemovingPasses(array());
10451048
}
1046-
$container->getCompilerPassConfig()->setBeforeRemovingPasses(array(new AddAnnotationsCachedReaderPass(), new AddConstraintValidatorsPass(), new TranslatorPass('translator.default', 'translation.reader')));
1049+
$container->getCompilerPassConfig()->setBeforeRemovingPasses(array(new AddConstraintValidatorsPass(), new TranslatorPass('translator.default', 'translation.reader')));
1050+
$container->getCompilerPassConfig()->setAfterRemovingPasses(array(new AddAnnotationsCachedReaderPass()));
1051+
1052+
if (!$compile) {
1053+
return $container;
1054+
}
10471055
$container->compile();
10481056

10491057
return self::$containerCache[$cacheKey] = $container;
@@ -1136,3 +1144,15 @@ private function assertCachePoolServiceDefinitionIsCreated(ContainerBuilder $con
11361144
}
11371145
}
11381146
}
1147+
1148+
/**
1149+
* Simulates ReplaceAliasByActualDefinitionPass.
1150+
*/
1151+
class TestAnnotationsPass implements CompilerPassInterface
1152+
{
1153+
public function process(ContainerBuilder $container)
1154+
{
1155+
$container->setDefinition('annotation_reader', $container->getDefinition('annotations.cached_reader'));
1156+
$container->removeDefinition('annotations.cached_reader');
1157+
}
1158+
}

0 commit comments

Comments
 (0)