Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f971882

Browse files
committed
[Cache] Fix possible infinite loop in CachePoolPass
1 parent 9d45d95 commit f971882

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,10 @@ public function process(ContainerBuilder $container)
209209
}
210210

211211
$notAliasedCacheClearerId = $this->cacheClearerId;
212-
while ($container->hasAlias($this->cacheClearerId)) {
213-
$this->cacheClearerId = (string) $container->getAlias($this->cacheClearerId);
212+
while ($container->hasAlias($notAliasedCacheClearerId)) {
213+
$notAliasedCacheClearerId = (string) $container->getAlias($notAliasedCacheClearerId);
214214
}
215-
if ($container->hasDefinition($this->cacheClearerId)) {
215+
if ($container->hasDefinition($notAliasedCacheClearerId)) {
216216
$clearers[$notAliasedCacheClearerId] = $allPools;
217217
}
218218

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

0 commit comments

Comments
 (0)