8000 [Cache] Fix possible infinite loop in `CachePoolPass` · symfony/symfony@58212ad · GitHub
[go: up one dir, main page]

Skip to content

Commit 58212ad

Browse files
committed
[Cache] Fix possible infinite loop in CachePoolPass
1 parent dd5902c commit 58212ad

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

src/Symfony/Component/Cache/DependencyInjection/CachePoolPass.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,11 @@ public function process(ContainerBuilder $container)
181181
$container->removeDefinition('cache.early_expiration_handler');
182182
}
183183

184-
$notAliasedCacheClearerId = $aliasedCacheClearerId = 'cache.global_clearer';
185-
while ($container->hasAlias('cache.global_clearer')) {
186-
$aliasedCacheClearerId = (string) $container->getAlias('cache.global_clearer');
184+
$notAliasedCacheClearerId = 'cache.global_clearer';
185+
while ($container->hasAlias($notAliasedCacheClearerId)) {
186+
$notAliasedCacheClearerId = (string) $container->getAlias($notAliasedCacheClearerId);
187187
}
188-
if ($container->hasDefinition($aliasedCacheClearerId)) {
188+
if ($container->hasDefinition($notAliasedCacheClearerId)) {
189189
$clearers[$notAliasedCacheClearerId] = $allPools;
190190
}
191191

src/Symfony/Component/Cache/Tests/DependencyInjection/CachePoolPassTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Symfony\Component\DependencyInjection\ContainerBuilder;
2323
use Symfony\Component\DependencyInjection\Definition;
2424
use Symfony\Component\DependencyInjection\Reference;
25+
use Symfony\Component\HttpKernel\CacheClearer\Psr6CacheClearer;
2526

2627
class CachePoolPassTest extends TestCase
2728
{
@@ -233,4 +234,35 @@ public function testChainAdapterPool()
233234
$this->assertInstanceOf(ChildDefinition::class, $doctrineCachePool);
234235
$this->assertSame('cache.app', $doctrineCachePool->getParent());
235236
}
237+
238+
public function testGlobalClearerAlias()
239+
{
240+
$container = new ContainerBuilder();
241+
$container->setParameter('kernel.container_class', 'app');
242+
$container->setParameter('kernel.project_dir', 'foo');
243+
244+
$container->register('cache.default_clearer', Psr6CacheClearer::class);
245+
246+
$container->setDefinition('cache.system_clearer', new ChildDefinition('cache.default_clearer'));
247+
248+
$container->setDefinition('cache.foo_bar_clearer', new ChildDefinition('cache.default_clearer'));
249+
$container->setAlias('cache.global_clearer', 'cache.foo_bar_clearer');
250+
251+
$container->register('cache.adapter.array', ArrayAdapter::class)
252+
->setAbstract(true)
253+
->addTag('cache.pool');
254+
255+
$cachePool = new ChildDefinition('cache.adapter.array');
256+
$cachePool->addTag('cache.pool', ['clearer' => 'cache.system_clearer']);
257+
$container->setDefinition('app.cache_pool', $cachePool);
258+
259+
$this->cachePoolPass->process($container);
260+
261+
$definition = $container->getDefinition('cache.foo_bar_clearer');
262+
263+
$this->assertTrue($definition->hasTag('cache.pool.clearer'));
264+
$this->assertCount(1, $arguments = $definition->getArguments());
265+
$this->assertIsArray($firstArgument = reset($arguments));
266+
$this->assertArrayHasKey('app.cache_pool', $firstArgument);
267+
}
236268
}

0 commit comments

Comments
 (0)
0