Skip to content

Commit

Permalink
Fix cache compatibility with cache pools
Browse files Browse the repository at this point in the history
  • Loading branch information
ostrolucky committed Jun 1, 2021
1 parent 0e0bc9d commit 9cc34c6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
9 changes: 7 additions & 2 deletions DependencyInjection/Compiler/CacheCompatibilityPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Doctrine\Common\Cache\Psr6\CacheAdapter;
use Doctrine\Common\Cache\Psr6\DoctrineProvider;
use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
Expand Down Expand Up @@ -34,10 +35,14 @@ public function process(ContainerBuilder $container): void

$aliasId = (string) $methodCall[1][0];
$definitionId = (string) $container->getAlias($aliasId);
$isPsr6 = is_a($container->getDefinition($definitionId)->getClass(), CacheItemPoolInterface::class, true);
$definition = $container->getDefinition($definitionId);
$shouldBePsr6 = self::CACHE_METHODS_PSR6_SUPPORT_MAP[$methodCall[0]];

if ($shouldBePsr6 === $isPsr6) {
while (! $definition->getClass() && $definition instanceof ChildDefinition) {
$definition = $container->findDefinition($definition->getParent());
}

if ($shouldBePsr6 === is_a($definition->getClass(), CacheItemPoolInterface::class, true)) {
continue;
}

Expand Down
16 changes: 14 additions & 2 deletions Tests/DependencyInjection/Compiler/CacheCompatibilityPassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,29 @@ class CacheCompatibilityPassTest extends TestCase
{
use ExpectDeprecationTrait;

public function testLegacyCacheConfigUsingServiceDefinedByApplication(): void
public function testCacheConfigUsingCachePools(): void
{
$this->expectNotToPerformAssertions();
(new class () extends TestKernel {
public function registerContainerConfiguration(LoaderInterface $loader): void
{
parent::registerContainerConfiguration($loader);
$loader->load(static function (ContainerBuilder $containerBuilder): void {
$containerBuilder->loadFromExtension('framework', [
'cache' => [
'pools' => [
'doctrine.system_cache_pool' => ['adapter' => 'cache.system'],
],
],
]);
$containerBuilder->loadFromExtension(
'doctrine',
['orm' => ['query_cache_driver' => ['type' => 'service', 'id' => 'custom_cache_service']]]
[
'orm' => [
'query_cache_driver' => ['type' => 'service', 'id' => 'custom_cache_service'],
'result_cache_driver' => ['type' => 'pool', 'pool' => 'doctrine.system_cache_pool'],
],
]
);
$containerBuilder->setDefinition(
'custom_cache_service',
Expand Down

0 comments on commit 9cc34c6

Please sign in to comment.