Skip to content

Commit 1adc468

Browse files
Merge branch '4.0'
* 4.0: [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 [Serializer] remove unneeded php doc line Yaml parser regression with comments and non-strings Fixed broken tests [TwigBridge] Apply some changes to support Bootstrap4-stable
2 parents 92293ec + 2d7ad46 commit 1adc468

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
@@ -1137,7 +1137,9 @@ private function registerAnnotationsConfiguration(array $config, ContainerBuilde
11371137
->replaceArgument(2, $config['debug'])
11381138
// temporary property to lazy-reference the cache provider without using it until AddAnnotationsCachedReaderPass runs
11391139
->setProperty('cacheProviderBackup', new ServiceClosureArgument(new Reference($cacheService)))
1140+
->addTag('annotations.cached_reader')
11401141
;
1142+
11411143
$container->setAlias('annotation_reader', 'annotations.cached_reader')->setPrivate(true);
11421144
$container->setAlias(Reader::class, new Alias('annotations.cached_reader', false));
11431145
} 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()
@@ -1062,10 +1065,10 @@ protected function createContainer(array $data = array())
10621065
), $data)));
10631066
}
10641067

1065-
protected function createContainerFromFile($file, $data = array(), $resetCompilerPasses = true)
1068+
protected function createContainerFromFile($file, $data = array(), $resetCompilerPasses = true, $compile = true)
10661069
{
10671070
$cacheKey = md5(get_class($this).$file.serialize($data));
1068-
if (isset(self::$containerCache[$cacheKey])) {
1071+
if ($compile && isset(self::$containerCache[$cacheKey])) {
10691072
return self::$containerCache[$cacheKey];
10701073
}
10711074
$container = $this->createContainer($data);
@@ -1076,7 +1079,12 @@ protected function createContainerFromFile($file, $data = array(), $resetCompile
10761079
$container->getCompilerPassConfig()->setOptimizationPasses(array());
10771080
$container->getCompilerPassConfig()->setRemovingPasses(array());
10781081
}
1079-
$container->getCompilerPassConfig()->setBeforeRemovingPasses(array(new AddAnnotationsCachedReaderPass(), new AddConstraintValidatorsPass(), new TranslatorPass('translator.default', 'translation.reader')));
1082+
$container->getCompilerPassConfig()->setBeforeRemovingPasses(array(new AddConstraintValidatorsPass(), new TranslatorPass('translator.default', 'translation.reader')));
1083+
$container->getCompilerPassConfig()->setAfterRemovingPasses(array(new AddAnnotationsCachedReaderPass()));
1084+
1085+
if (!$compile) {
1086+
return $container;
1087+
}
10801088
$container->compile();
10811089

10821090
return self::$containerCache[$cacheKey] = $container;
@@ -1169,3 +1177,15 @@ private function assertCachePoolServiceDefinitionIsCreated(ContainerBuilder $con
11691177
}
11701178
}
11711179
}
1180+
1181+
/**
1182+
* Simulates ReplaceAliasByActualDefinitionPass.
1183+
*/
1184+
class TestAnnotationsPass implements CompilerPassInterface
1185+
{
1186+
public function process(ContainerBuilder $container)
1187+
{
1188+
$container->setDefinition('annotation_reader', $container->getDefinition('annotations.cached_reader'));
1189+
$container->removeDefinition('annotations.cached_reader');
1190+
}
1191+
}

0 commit comments

Comments
 (0)