fix processing chain adapter based cache pool
This commit is contained in:
parent
b9a0b33540
commit
8d7fa32d15
@ -103,7 +103,12 @@ class CachePoolPass implements CompilerPassInterface
|
|||||||
if (ChainAdapter::class === $class) {
|
if (ChainAdapter::class === $class) {
|
||||||
$adapters = [];
|
$adapters = [];
|
||||||
foreach ($adapter->getArgument(0) as $provider => $adapter) {
|
foreach ($adapter->getArgument(0) as $provider => $adapter) {
|
||||||
|
if ($adapter instanceof ChildDefinition) {
|
||||||
|
$chainedPool = $adapter;
|
||||||
|
} else {
|
||||||
$chainedPool = $adapter = new ChildDefinition($adapter);
|
$chainedPool = $adapter = new ChildDefinition($adapter);
|
||||||
|
}
|
||||||
|
|
||||||
$chainedTags = [\is_int($provider) ? [] : ['provider' => $provider]];
|
$chainedTags = [\is_int($provider) ? [] : ['provider' => $provider]];
|
||||||
$chainedClass = '';
|
$chainedClass = '';
|
||||||
|
|
||||||
|
@ -12,7 +12,9 @@
|
|||||||
namespace Symfony\Component\Cache\Tests\DependencyInjection;
|
namespace Symfony\Component\Cache\Tests\DependencyInjection;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Symfony\Component\Cache\Adapter\ApcuAdapter;
|
||||||
use Symfony\Component\Cache\Adapter\ArrayAdapter;
|
use Symfony\Component\Cache\Adapter\ArrayAdapter;
|
||||||
|
use Symfony\Component\Cache\Adapter\ChainAdapter;
|
||||||
use Symfony\Component\Cache\Adapter\RedisAdapter;
|
use Symfony\Component\Cache\Adapter\RedisAdapter;
|
||||||
use Symfony\Component\Cache\DependencyInjection\CachePoolPass;
|
use Symfony\Component\Cache\DependencyInjection\CachePoolPass;
|
||||||
use Symfony\Component\DependencyInjection\ChildDefinition;
|
use Symfony\Component\DependencyInjection\ChildDefinition;
|
||||||
@ -174,4 +176,42 @@ class CachePoolPassTest extends TestCase
|
|||||||
|
|
||||||
$this->cachePoolPass->process($container);
|
$this->cachePoolPass->process($container);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testChainAdapterPool()
|
||||||
|
{
|
||||||
|
$container = new ContainerBuilder();
|
||||||
|
$container->setParameter('kernel.container_class', 'app');
|
||||||
|
$container->setParameter('kernel.project_dir', 'foo');
|
||||||
|
|
||||||
|
$container->register('cache.adapter.array', ArrayAdapter::class)
|
||||||
|
->addTag('cache.pool');
|
||||||
|
$container->register('cache.adapter.apcu', ApcuAdapter::class)
|
||||||
|
->setArguments([null, 0, null])
|
||||||
|
->addTag('cache.pool');
|
||||||
|
$container->register('cache.chain', ChainAdapter::class)
|
||||||
|
->addArgument(['cache.adapter.array', 'cache.adapter.apcu'])
|
||||||
|
->addTag('cache.pool');
|
||||||
|
$container->setDefinition('cache.app', new ChildDefinition('cache.chain'))
|
||||||
|
->addTag('cache.pool');
|
||||||
|
$container->setDefinition('doctrine.result_cache_pool', new ChildDefinition('cache.app'))
|
||||||
|
->addTag('cache.pool');
|
||||||
|
|
||||||
|
$this->cachePoolPass->process($container);
|
||||||
|
|
||||||
|
$appCachePool = $container->getDefinition('cache.app');
|
||||||
|
$this->assertInstanceOf(ChildDefinition::class, $appCachePool);
|
||||||
|
$this->assertSame('cache.chain', $appCachePool->getParent());
|
||||||
|
|
||||||
|
$chainCachePool = $container->getDefinition('cache.chain');
|
||||||
|
$this->assertNotInstanceOf(ChildDefinition::class, $chainCachePool);
|
||||||
|
$this->assertCount(2, $chainCachePool->getArgument(0));
|
||||||
|
$this->assertInstanceOf(ChildDefinition::class, $chainCachePool->getArgument(0)[0]);
|
||||||
|
$this->assertSame('cache.adapter.array', $chainCachePool->getArgument(0)[0]->getParent());
|
||||||
|
$this->assertInstanceOf(ChildDefinition::class, $chainCachePool->getArgument(0)[1]);
|
||||||
|
$this->assertSame('cache.adapter.apcu', $chainCachePool->getArgument(0)[1]->getParent());
|
||||||
|
|
||||||
|
$doctrineCachePool = $container->getDefinition('doctrine.result_cache_pool');
|
||||||
|
$this->assertInstanceOf(ChildDefinition::class, $doctrineCachePool);
|
||||||
|
$this->assertSame('cache.app', $doctrineCachePool->getParent());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user