Skip to content

Commit 53c18cf

Browse files
bug #60594 [Cache] Fix using a ChainAdapter as an adapter for a pool (IndraGunawan)
This PR was squashed before being merged into the 6.4 branch. Discussion ---------- [Cache] Fix using a `ChainAdapter` as an adapter for a pool | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Issues | Fix #60579 | License | MIT ### How to reproduce ``` symfony new --webapp --version lts 6.4 ``` ```yaml # services.yaml services: _defaults: autowire: true autoconfigure: true my_cache.chain: class: Symfony\Component\Cache\Adapter\ChainAdapter arguments: - [ '`@cache`.adapter.array', '`@cache`.adapter.filesystem' ] tags: - { name: cache.pool, namespace: 'my-custom-ns' } ``` ```yaml # cache.yaml framework: cache: pools: my_chain_pool: adapter: my_cache.chain ``` The error: failing tests: https://github.com/symfony/symfony/actions/runs/15363463181/job/43233401667?pr=60594 ``` !! In Definition.php line 295: !! !! The argument "0" doesn't exist in class "Symfony\Component\Cache\Adapter\ChainAdapter". ``` Commits ------- b24e3cd [Cache] Fix using a `ChainAdapter` as an adapter for a pool
2 parents a880ecb + b24e3cd commit 53c18cf

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,11 @@ public function process(ContainerBuilder $container)
5858
continue;
5959
}
6060
$class = $adapter->getClass();
61+
$providers = $adapter->getArguments();
6162
while ($adapter instanceof ChildDefinition) {
6263
$adapter = $container->findDefinition($adapter->getParent());
6364
$class = $class ?: $adapter->getClass();
65+
$providers += $adapter->getArguments();
6466
if ($t = $adapter->getTag('cache.pool')) {
6567
$tags[0] += $t[0];
6668
}
@@ -90,7 +92,7 @@ public function process(ContainerBuilder $container)
9092

9193
if (ChainAdapter::class === $class) {
9294
$adapters = [];
93-
foreach ($adapter->getArgument(0) as $provider => $adapter) {
95+
foreach ($providers['index_0'] ?? $providers[0] as $provider => $adapter) {
9496
if ($adapter instanceof ChildDefinition) {
9597
$chainedPool = $adapter;
9698
} else {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,8 @@ public function testChainAdapterPool()
209209
$container->register('cache.adapter.apcu', ApcuAdapter::class)
210210
->setArguments([null, 0, null])
211211
->addTag('cache.pool');
212-
$container->register('cache.chain', ChainAdapter::class)
212+
$container->register('cache.adapter.chain', ChainAdapter::class);
213+
$container->setDefinition('cache.chain', new ChildDefinition('cache.adapter.chain'))
213214
->addArgument(['cache.adapter.array', 'cache.adapter.apcu'])
214215
->addTag('cache.pool');
215216
$container->setDefinition('cache.app', new ChildDefinition('cache.chain'))
@@ -224,7 +225,7 @@ public function testChainAdapterPool()
224225
$this->assertSame('cache.chain', $appCachePool->getParent());
225226

226227
$chainCachePool = $container->getDefinition('cache.chain');
227-
$this->assertNotInstanceOf(ChildDefinition::class, $chainCachePool);
228+
$this->assertInstanceOf(ChildDefinition::class, $chainCachePool);
228229
$this->assertCount(2, $chainCachePool->getArgument(0));
229230
$this->assertInstanceOf(ChildDefinition::class, $chainCachePool->getArgument(0)[0]);
230231
$this->assertSame('cache.adapter.array', $chainCachePool->getArgument(0)[0]->getParent());

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy