8000 bug #21381 [FrameworkBundle] Dont wire "annotations.cached_reader" be… · symfony/symfony@99d29c0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 99d29c0

Browse files
committed
bug #21381 [FrameworkBundle] Dont wire "annotations.cached_reader" before removing passes (nicolas-grekas)
This PR was merged into the 3.2 branch. Discussion ---------- [FrameworkBundle] Dont wire "annotations.cached_reader" before removing passes | Q | A | ------------- | --- | Branch? | 3.2 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #21339 | License | MIT | Doc PR | - This PR basically reverts #20601 and wires "annotations.cached_reader" later, so that any compiler passes needing "annotation_reader" at compile time don't get any cache - anyway, it's useless at compile time. Commits ------- e59f0e0 [FrameworkBundle] Dont wire "annotations.cached_reader" before removing passes
2 parents 5949f7d + e59f0e0 commit 99d29c0

File tree

8 files changed

+66
-27
lines changed

8 files changed

+66
-27
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
13+
14+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15+
use Symfony\Component\DependencyInjection\ContainerBuilder;
16+
17+
/**
18+
* @internal
19+
*/
20+
class AddAnnotationsCachedReaderPass implements CompilerPassInterface
21+
{
22+
/**
23+
* {@inheritdoc}
24+
*/
25+
public function process(ContainerBuilder $container)
26+
{
27+
// "annotations.cached_reader" is wired late so that any passes using
28+
// "annotation_reader" at build time don't get any cache
29+
if ($container->hasDefinition('annotations.cached_reader')) {
30+
$container->setAlias('annotation_reader', 'annotations.cached_reader');
31+
}
32+
}
33+
}

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

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
1313

14-
use Symfony\Component\Cache\Adapter\AbstractAdapter;
1514
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
1615
use Symfony\Component\DependencyInjection\ContainerBuilder;
1716
use Symfony\Component\DependencyInjection\Reference;
@@ -39,22 +38,5 @@ public function process(ContainerBuilder $container)
3938
}
4039
}
4140
}
42-
43-
if (!$container->has('cache.annotations')) {
44-
return;
45-
}
46-
$factory = array(AbstractAdapter::class, 'createSystemCache');
47-
$annotationsPool = $container->getDefinition('cache.annotations');
48-
if ($factory !== $annotationsPool->getFactory() || 4 !== count($annotationsPool->getArguments())) {
49-
return;
50-
}
51-
if ($container->has('monolog.logger.cache')) {
52-
$annotationsPool->addArgument(new Reference('monolog.logger.cache'));
53-
} elseif ($container->has('cache.system')) {
54-
$systemPool = $container->getDefinition('cache.system');
55-
if ($factory === $systemPool->getFactory() && 5 <= count($systemArgs = $systemPool->getArguments())) {
56-
$annotationsPool->addArgument($systemArgs[4]);
57-
}
58-
}
5941
}
6042
}

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

Lines changed: B41A 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,8 @@ private function registerAnnotationsConfiguration(array $config, ContainerBuilde
10431043
->replaceArgument(2, $config['debug'])
10441044
->addAutowiringType(Reader::class)
10451045
;
1046-
$container->setAlias('annotation_reader', 'annotations.cached_reader');
1046+
} else {
1047+
$container->removeDefinition('annotations.cached_reader');
10471048
}
10481049
}
10491050

src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle;
1313

14+
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddAnnotationsCachedReaderPass;
1415
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConstraintValidatorsPass;
1516
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddDebugLogProcessorPass;
1617
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddValidatorInitializersPass;
@@ -79,6 +80,7 @@ public function build(ContainerBuilder $container)
7980
$container->addCompilerPass(new RegisterListenersPass(), PassConfig::TYPE_BEFORE_REMOVING);
8081
$container->addCompilerPass(new TemplatingPass());
8182
$container->addCompilerPass(new AddConstraintValidatorsPass(), PassConfig::TYPE_BEFORE_REMOVING);
83+
$container->addCompilerPass(new AddAnnotationsCachedReaderPass(), PassConfig::TYPE_BEFORE_REMOVING);
8284
$container->addCompilerPass(new AddValidatorInitializersPass());
8385
$container->addCompilerPass(new AddConsoleCommandPass());
8486
$container->addCompilerPass(new FormPass());

src/Symfony/Bundle/FrameworkBundle/Resources/config/cache.xml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,8 @@
2222
<tag name="cache.pool" />
2323
</service>
2424

25-
<service id="cache.annotations" class="Symfony\Component\Cache\Adapter\AdapterInterface" public="false">
26-
<factory class="Symfony\Component\Cache\Adapter\AbstractAdapter" method="createSystemCache" />
27-
<tag name="cache.pool" clearer="cache.default_clearer" />
28-
<argument /> <!-- namespace -->
29-
<argument>0</argument> <!-- default lifetime -->
30-
<argument /> <!-- version -->
31-
<argument>%kernel.cache_dir%/pools</argument>
25+
<service id="cache.annotations" parent="cache.system" public="false">
26+
<tag name="cache.pool" />
3227
</service>
3328

3429
<service id="cache.adapter.system" class="Symfony\Component\Cache\Adapter\AdapterInterface" abstract="true">

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,6 @@ public function testAnnotations()
440440
$container = $this->createContainerFromFile('full');
441441

442442
$this->assertEquals($container->getParameter('kernel.cache_dir').'/annotations', $container->getDefinition('annotations.filesystem_cache')->getArgument(0));
443-
$this->assertSa 10000 me('annotations.cached_reader', (string) $container->getAlias('annotation_reader'));
444443
$this->assertSame('annotations.filesystem_cache', (string) $container->getDefinition('annotations.cached_reader')->getArgument(1));
445444
}
446445

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\DependencyInjection;
13+
14+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15+
use Symfony\Component\DependencyInjection\ContainerBuilder;
16+
17+
class AnnotationReaderPass implements CompilerPassInterface
18+
{
19+
public function process(ContainerBuilder $container)
20+
{
21+
// simulate using "annotation_reader" in a compiler pass
22+
$container->get('annotation_reader');
23+
}
24+
}

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

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

1414
use Symfony\Component\HttpKernel\Bundle\Bundle;
1515
use Symfony\Component\DependencyInjection\ContainerBuilder;
16+
use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\DependencyInjection\AnnotationReaderPass;
1617
use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\DependencyInjection\Config\CustomConfig;
1718

1819
class TestBundle extends Bundle
@@ -25,5 +26,7 @@ public function build(ContainerBuilder $container)
2526
$extension = $container->getExtension('test');
2627

2728
$extension->setCustomConfig(new CustomConfig());
29+
30+
$container->addCompilerPass(new AnnotationReaderPass());
2831
}
2932
}

0 commit comments

Comments
 (0)
0