8000 bug #20601 [FrameworkBundle] Don't rely on any parent definition for … · symfony/symfony@24c40e0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 24c40e0

Browse files
committed
bug #20601 [FrameworkBundle] Don't rely on any parent definition for "cache.annotations" (nicolas-grekas)
This PR was merged into the 3.2 branch. Discussion ---------- [FrameworkBundle] Don't rely on any parent definition for "cache.annotations" | Q | A | ------------- | --- | Branch? | 3.2 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Instead of a generic approach that failed in #20537, let's focus on the `cache.annotations` service, which is the one that needs special care because it can be required while the container is being built. See e.g.: - #20234 - http://stackoverflow.com/questions/39625863/vichuploadbundle-inb-symfony-3-cant-load-cache-annotations-service/40626277 - schmittjoh/JMSDiExtraBundle#262 When the service is required at build time, we can't provide it a logger, because no logger service is ready at that time. Still, that doesn't prevent the service from working. The late `CachePoolClearerPass` wires the logger for later instantiations so that `cache.annotations` has a properly configured logger *for the next requests*. Commits ------- f62b820 [FrameworkBundle] Dont rely on any parent definition for "cache.annotations"
2 parents 942cfc9 + f62b820 commit 24c40e0

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

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

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

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

14+
use Symfony\Component\Cache\Adapter\AbstractAdapter;
1415
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
1516
use Symfony\Component\DependencyInjection\ContainerBuilder;
1617
use Symfony\Component\DependencyInjection\Reference;
@@ -38,5 +39,22 @@ public function process(ContainerBuilder $container)
3839
}
3940
}
4041
}
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+
}
4159
}
4260
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,7 @@ private function registerPropertyInfoConfiguration(array $config, ContainerBuild
12381238
private function registerCacheConfiguration(array $config, ContainerBuilder $container)
12391239
{
12401240
$version = substr(str_replace('/', '-', base64_encode(hash('sha256', uniqid(mt_rand(), true), true))), 0, 22);
1241+
$container->getDefinition('cache.annotations')->replaceArgument(2, $version);
12411242
$container->getDefinition('cache.adapter.apcu')->replaceArgument(2, $version);
12421243
$container->getDefinition('cache.adapter.system')->replaceArgument(2, $version);
12431244
$container->getDefinition('cache.adapter.filesystem')->replaceArgument(2, $config['directory']);

src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ public function build(ContainerBuilder $container)
9393
$container->addCompilerPass(new SerializerPass());
9494
$container->addCompilerPass(new PropertyInfoPass());
9595
$container->addCompilerPas 8000 s(new ControllerArgumentValueResolverPass());
96-
$container->addCompilerPass(new CachePoolPass());
96+
$container->addCompilerPass(new CachePoolPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 32);
9797
$container->addCompilerPass(new ValidateWorkflowsPass());
9898
$container->addCompilerPass(new CachePoolClearerPass(), PassConfig::TYPE_AFTER_REMOVING);
9999

100100
if ($container->getParameter('kernel.debug')) {
101-
$container->addCompilerPass(new AddDebugLogProcessorPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, -1);
101+
$container->addCompilerPass(new AddDebugLogProcessorPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, -32);
102102
$container->addCompilerPass(new UnusedTagsPass(), PassConfig::TYPE_AFTER_REMOVING);
103103
$container->addCompilerPass(new ContainerBuilderDebugDumpPass(), PassConfig::TYPE_AFTER_REMOVING);
104104
$container->addCompilerPass(new CompilerDebugDumpPass(), PassConfig::TYPE_AFTER_REMOVING);

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

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

25-
<service id="cache.annotations" parent="cache.system" public="false">
26-
<tag name="cache.pool" />
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>
2732
</service>
2833

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

0 commit comments

Comments
 (0)
0