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

Skip to content

Commit db60d1f

Browse files
[Cache] fix wiring async cache recomputing in debug mode
1 parent c4b1ec5 commit db60d1f

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,15 @@ private function addToCollector(string $id, string $name, ContainerBuilder $cont
7272
}
7373
$recorder->setArguments([new Reference($innerId = $id.$this->cachePoolRecorderInnerSuffix)]);
7474

75+
foreach ($definition->getMethodCalls() as [$method, $args]) {
76+
if ('setCallbackWrapper' !== $method || !$args[0] instanceof Definition || !($args[0]->getArguments()[2] ?? null) instanceof Definition) {
77+
continue;
78+
}
79+
if ([new Reference($id), 'setCallbackWrapper'] == $args[0]->getArguments()[2]->getFactory()) {
80+
$args[0]->getArguments()[2]->setFactory([new Reference($innerId), 'setCallbackWrapper']);
81+
}
82+
}
83+
7584
$definition->setTags([]);
7685
$definition->setPublic(false);
7786

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Symfony\Component\Cache\Tests\Fixtures\ArrayCache;
2323
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
2424
use Symfony\Component\DependencyInjection\ContainerBuilder;
25+
use Symfony\Component\DependencyInjection\Definition;
2526
use Symfony\Component\DependencyInjection\Reference;
2627

2728
class CacheCollectorPassTest extends TestCase
@@ -31,6 +32,13 @@ public function testProcess()
3132
$container = new ContainerBuilder();
3233
$container
3334
->register('fs', FilesystemAdapter::class)
35+
->addMethodCall('setCallbackWrapper', [(new Definition())
36+
->addArgument(null)
37+
->addArgument(null)
38+
->addArgument((new Definition('callable'))
39+
->setFactory([new Reference('fs'), 'setCallbackWrapper'])
40+
),
41+
])
3442
->addTag('cache.pool');
3543
$container
3644
->register('tagged_fs', TagAwareAdapter::class)
@@ -60,6 +68,9 @@ public function testProcess()
6068
$this->assertSame(TagAwareAdapter::class, $container->getDefinition('php')->getClass());
6169

6270
$this->assertFalse($collector->isPublic(), 'The "data_collector.cache" should be private after processing');
71+
72+
$innerFs = $container->getDefinition('fs.recorder_inner');
73+
$this->assertEquals([new Reference('fs.recorder_inner'), 'setCallbackWrapper'], $innerFs->getMethodCalls()[0][1][0]->getArgument(2)->getFactory());
6374
}
6475

6576
public function testProcessCacheObjectsAreDecorated()

0 commit comments

Comments
 (0)