Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 58212ad

Browse filesBrowse files
committed
[Cache] Fix possible infinite loop in CachePoolPass
1 parent dd5902c commit 58212ad
Copy full SHA for 58212ad

File tree

2 files changed

+36
-4
lines changed
Filter options

2 files changed

+36
-4
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/DependencyInjection/CachePoolPass.php
+4-4Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Tests/DependencyInjection/CachePoolPassTest.php
+32Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.