feature #18667 [FrameworkBundle] Semantic config for app/system/pool caches (tgalopin, nicolas-grekas)
This PR was merged into the 3.1-dev branch. Discussion ---------- [FrameworkBundle] Semantic config for app/system/pool caches | Q | A | ------------- | --- | Branch? | 3.1 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #18625 | License | MIT | Doc PR | - Commits -------a2a567d
[FrameworkBundle] Simplify config for app/system/pool caches80a5508
[FrameworkBundle] Add cache adapters in semantic configuration
This commit is contained in:
commit
2849654595
@ -93,8 +93,8 @@ FrameworkBundle
|
||||
cache service. If you are using `serializer.mapping.cache.apc`, use
|
||||
`serializer.mapping.cache.doctrine.apc` instead.
|
||||
|
||||
* The `framework.serializer.cache` option has been deprecated. Configure a cache pool
|
||||
called `serializer` under `framework.cache.pools` instead.
|
||||
* The `framework.serializer.cache` option has been deprecated. Configure the
|
||||
`cache.serializer` service under `framework.cache.pools` instead.
|
||||
|
||||
Before:
|
||||
|
||||
@ -110,7 +110,7 @@ FrameworkBundle
|
||||
framework:
|
||||
cache:
|
||||
pools:
|
||||
serializer:
|
||||
cache.serializer:
|
||||
adapter: cache.adapter.apcu
|
||||
|
||||
HttpKernel
|
||||
|
@ -80,8 +80,8 @@ FrameworkBundle
|
||||
* The service `serializer.mapping.cache.apc` has been removed; use
|
||||
`serializer.mapping.cache.doctrine.apc` instead.
|
||||
|
||||
* The `framework.serializer.cache` option has been removed. Configure a cache pool
|
||||
called `serializer` under `framework.cache.pools` instead.
|
||||
* The `framework.serializer.cache` option has been removed. Configure the
|
||||
`cache.serializer` service under `framework.cache.pools` instead.
|
||||
|
||||
Before:
|
||||
|
||||
@ -97,7 +97,7 @@ FrameworkBundle
|
||||
framework:
|
||||
cache:
|
||||
pools:
|
||||
serializer:
|
||||
cache.serializer:
|
||||
adapter: cache.adapter.apcu
|
||||
```
|
||||
|
||||
|
@ -11,8 +11,10 @@
|
||||
|
||||
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
|
||||
|
||||
use Symfony\Component\Cache\Adapter\RedisAdapter;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\DefinitionDecorator;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
@ -44,13 +46,15 @@ class CachePoolPass implements CompilerPassInterface
|
||||
if ($pool->isAbstract()) {
|
||||
continue;
|
||||
}
|
||||
$tags[0]['namespace'] = $this->getNamespace($namespaceSuffix, isset($tags[0]['namespace']) ? $tags[0]['namespace'] : $id);
|
||||
while ($adapter instanceof DefinitionDecorator) {
|
||||
$adapter = $container->findDefinition($adapter->getParent());
|
||||
if ($t = $adapter->getTag('cache.pool')) {
|
||||
$tags[0] += $t[0];
|
||||
}
|
||||
}
|
||||
if (!isset($tags[0]['namespace'])) {
|
||||
$tags[0]['namespace'] = $this->getNamespace($namespaceSuffix, $id);
|
||||
}
|
||||
if (isset($tags[0]['clearer'])) {
|
||||
$clearer = $container->getDefinition($tags[0]['clearer']);
|
||||
} else {
|
||||
@ -58,8 +62,8 @@ class CachePoolPass implements CompilerPassInterface
|
||||
}
|
||||
unset($tags[0]['clearer']);
|
||||
|
||||
if (isset($tags[0]['provider']) && is_string($tags[0]['provider'])) {
|
||||
$tags[0]['provider'] = new Reference($tags[0]['provider']);
|
||||
if (isset($tags[0]['provider'])) {
|
||||
$tags[0]['provider'] = new Reference(static::getServiceProvider($container, $tags[0]['provider']));
|
||||
}
|
||||
$i = 0;
|
||||
foreach ($attributes as $attr) {
|
||||
@ -82,4 +86,24 @@ class CachePoolPass implements CompilerPassInterface
|
||||
{
|
||||
return substr(str_replace('/', '-', base64_encode(md5($id.$namespaceSuffix, true))), 0, 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public static function getServiceProvider(ContainerBuilder $container, $name)
|
||||
{
|
||||
if (0 === strpos($name, 'redis://')) {
|
||||
$dsn = $name;
|
||||
|
||||
if (!$container->hasDefinition($name = md5($dsn))) {
|
||||
$definition = new Definition(\Redis::class);
|
||||
$definition->setPublic(false);
|
||||
$definition->setFactory(array(RedisAdapter::class, 'createConnection'));
|
||||
$definition->setArguments(array($dsn));
|
||||
$container->setDefinition($name, $definition);
|
||||
}
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
}
|
||||
|
@ -558,25 +558,35 @@ class Configuration implements ConfigurationInterface
|
||||
->addDefaultsIfNotSet()
|
||||
->fixXmlConfig('pool')
|
||||
->children()
|
||||
->scalarNode('app')
|
||||
->info('App related cache pools configuration')
|
||||
->defaultValue('cache.adapter.filesystem')
|
||||
->end()
|
||||
->scalarNode('system')
|
||||
->info('System related cache pools configuration')
|
||||
->defaultValue('cache.adapter.filesystem')
|
||||
->end()
|
||||
->scalarNode('directory')->defaultValue('%kernel.cache_dir%/pools')->end()
|
||||
->scalarNode('default_doctrine_provider')->end()
|
||||
->scalarNode('default_psr6_provider')->end()
|
||||
->scalarNode('default_redis_provider')->defaultValue('redis://localhost')->end()
|
||||
->arrayNode('pools')
|
||||
->useAttributeAsKey('name')
|
||||
->prototype('array')
|
||||
->children()
|
||||
->scalarNode('adapter')
|
||||
->info('The cache pool adapter service to use as template definition.')
|
||||
->defaultValue('cache.adapter.shared')
|
||||
->end()
|
||||
->scalarNode('adapter')->defaultValue('cache.app')->end()
|
||||
->booleanNode('public')->defaultFalse()->end()
|
||||
->integerNode('default_lifetime')->end()
|
||||
->scalarNode('provider')
|
||||
->info('The service name to use as provider when the specified adapter needs one.')
|
||||
->end()
|
||||
->scalarNode('namespace')
|
||||
->info('The namespace where cached items are stored. Auto-generated by default. Set to false to disable namespacing.')
|
||||
->end()
|
||||
->scalarNode('clearer')->defaultValue('cache.default_pools_clearer')->end()
|
||||
->scalarNode('clearer')->defaultValue('cache.default_clearer')->end()
|
||||
->end()
|
||||
->end()
|
||||
->validate()
|
||||
->ifTrue(function ($v) { return isset($v['cache.app']) || isset($v['cache.system']); })
|
||||
->thenInvalid('"cache.app" and "cache.system" are reserved names')
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
|
@ -73,7 +73,7 @@ class FrameworkExtension extends Extension
|
||||
$loader->load('property_access.xml');
|
||||
|
||||
// Load Cache configuration first as it is used by other components
|
||||
$loader->load('cache_pools.xml');
|
||||
$loader->load('cache.xml');
|
||||
|
||||
$configuration = $this->getConfiguration($configs, $container);
|
||||
$config = $this->processConfiguration($configuration, $configs);
|
||||
@ -984,7 +984,7 @@ class FrameworkExtension extends Extension
|
||||
$chainLoader->replaceArgument(0, $serializerLoaders);
|
||||
|
||||
if (isset($config['cache']) && $config['cache']) {
|
||||
@trigger_error('The "framework.serializer.cache" option is deprecated since Symfony 3.1 and will be removed in 4.0. You can configure a cache pool called "serializer" under "framework.cache.pools" instead.', E_USER_DEPRECATED);
|
||||
@trigger_error('The "framework.serializer.cache" option is deprecated since Symfony 3.1 and will be removed in 4.0. Configure the "cache.serializer" service under "framework.cache.pools" instead.', E_USER_DEPRECATED);
|
||||
|
||||
$container->setParameter(
|
||||
'serializer.mapping.cache.prefix',
|
||||
@ -999,7 +999,7 @@ class FrameworkExtension extends Extension
|
||||
CacheClassMetadataFactory::class,
|
||||
array(
|
||||
new Reference('serializer.mapping.cache_class_metadata_factory.inner'),
|
||||
new Reference('cache.pool.serializer'),
|
||||
new Reference('cache.serializer'),
|
||||
)
|
||||
);
|
||||
$cacheMetadataFactory->setPublic(false);
|
||||
@ -1037,13 +1037,26 @@ class FrameworkExtension extends Extension
|
||||
|
||||
private function registerCacheConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
|
||||
{
|
||||
foreach ($config['pools'] as $name => $poolConfig) {
|
||||
$poolDefinition = new DefinitionDecorator($poolConfig['adapter']);
|
||||
$poolDefinition->setPublic($poolConfig['public']);
|
||||
unset($poolConfig['adapter'], $poolConfig['public']);
|
||||
$container->getDefinition('cache.adapter.filesystem')->replaceArgument(2, $config['directory']);
|
||||
|
||||
$poolDefinition->addTag('cache.pool', $poolConfig);
|
||||
$container->setDefinition('cache.pool.'.$name, $poolDefinition);
|
||||
foreach (array('doctrine', 'psr6', 'redis') as $name) {
|
||||
if (isset($config[$name = 'default_'.$name.'_provider'])) {
|
||||
$container->setAlias('cache.'.$name, Compiler\CachePoolPass::getServiceProvider($container, $config[$name]));
|
||||
}
|
||||
}
|
||||
foreach (array('app', 'system') as $name) {
|
||||
$config['pools']['cache.'.$name] = array(
|
||||
'adapter' => $config[$name],
|
||||
'public' => true,
|
||||
);
|
||||
}
|
||||
foreach ($config['pools'] as $name => $pool) {
|
||||
$definition = new DefinitionDecorator($pool['adapter']);
|
||||
$definition->setPublic($pool['public']);
|
||||
unset($pool['adapter'], $pool['public']);
|
||||
|
||||
$definition->addTag('cache.pool', $pool);
|
||||
$container->setDefinition($name, $definition);
|
||||
}
|
||||
|
||||
$this->addClassesToCompile(array(
|
||||
|
@ -6,30 +6,24 @@
|
||||
|
||||
<services>
|
||||
|
||||
<service id="cache.default_pools_clearer" class="Symfony\Component\HttpKernel\CacheClearer\Psr6CacheClearer" public="false">
|
||||
<tag name="kernel.cache_clearer" />
|
||||
<service id="cache.app" parent="cache.adapter.filesystem">
|
||||
<tag name="cache.pool" />
|
||||
</service>
|
||||
|
||||
<service id="cache.adapter.shared" alias="cache.adapter.filesystem" />
|
||||
<service id="cache.adapter.local" alias="cache.adapter.filesystem" />
|
||||
|
||||
<service id="cache.pool.shared" parent="cache.adapter.shared">
|
||||
<tag name="cache.pool" clearer="cache.default_pools_clearer" />
|
||||
<service id="cache.system" parent="cache.adapter.filesystem">
|
||||
<tag name="cache.pool" />
|
||||
</service>
|
||||
|
||||
<service id="cache.pool.local" parent="cache.adapter.local">
|
||||
<tag name="cache.pool" clearer="cache.default_pools_clearer" />
|
||||
<service id="cache.validator" parent="cache.system" public="false">
|
||||
<tag name="cache.pool" />
|
||||
</service>
|
||||
|
||||
<service id="cache.pool.validator" parent="cache.adapter.local" public="false">
|
||||
<tag name="cache.pool" clearer="cache.default_pools_clearer" />
|
||||
</service>
|
||||
|
||||
<service id="cache.pool.serializer" parent="cache.adapter.local" public="false">
|
||||
<tag name="cache.pool" clearer="cache.default_pools_clearer" />
|
||||
<service id="cache.serializer" parent="cache.system" public="false">
|
||||
<tag name="cache.pool" />
|
||||
</service>
|
||||
|
||||
<service id="cache.adapter.apcu" class="Symfony\Component\Cache\Adapter\ApcuAdapter" abstract="true">
|
||||
<tag name="cache.pool" clearer="cache.default_clearer" />
|
||||
<tag name="monolog.logger" channel="cache" />
|
||||
<argument /> <!-- namespace -->
|
||||
<argument /> <!-- default lifetime -->
|
||||
@ -39,6 +33,7 @@
|
||||
</service>
|
||||
|
||||
<service id="cache.adapter.doctrine" class="Symfony\Component\Cache\Adapter\DoctrineAdapter" abstract="true">
|
||||
<tag name="cache.pool" provider="cache.default_doctrine_provider" clearer="cache.default_clearer" />
|
||||
<tag name="monolog.logger" channel="cache" />
|
||||
<argument /> <!-- Doctrine provider service -->
|
||||
<argument /> <!-- namespace -->
|
||||
@ -49,6 +44,7 @@
|
||||
</service>
|
||||
|
||||
<service id="cache.adapter.filesystem" class="Symfony\Component\Cache\Adapter\FilesystemAdapter" abstract="true">
|
||||
<tag name="cache.pool" clearer="cache.default_clearer" />
|
||||
<tag name="monolog.logger" channel="cache" />
|
||||
<argument /> <!-- namespace -->
|
||||
<argument /> <!-- default lifetime -->
|
||||
@ -59,14 +55,16 @@
|
||||
</service>
|
||||
|
||||
<service id="cache.adapter.psr6" class="Symfony\Component\Cache\Adapter\ProxyAdapter" abstract="true">
|
||||
<tag name="cache.pool" provider="cache.default_psr6_provider" clearer="cache.default_clearer" />
|
||||
<argument /> <!-- PSR-6 provider service -->
|
||||
<argument /> <!-- namespace -->
|
||||
<argument /> <!-- default lifetime -->
|
||||
</service>
|
||||
|
||||
<service id="cache.adapter.redis" class="Symfony\Component\Cache\Adapter\RedisAdapter" abstract="true">
|
||||
<tag name="cache.pool" provider="cache.default_redis_provider" clearer="cache.default_clearer" />
|
||||
<tag name="monolog.logger" channel="cache" />
|
||||
<argument /> <!-- Redis connection object -->
|
||||
<argument /> <!-- Redis connection service -->
|
||||
<argument /> <!-- namespace -->
|
||||
<argument /> <!-- default lifetime -->
|
||||
<call method="setLogger">
|
||||
@ -74,5 +72,9 @@
|
||||
</call>
|
||||
</service>
|
||||
|
||||
<service id="cache.default_clearer" class="Symfony\Component\HttpKernel\CacheClearer\Psr6CacheClearer" public="false">
|
||||
<tag name="kernel.cache_clearer" />
|
||||
</service>
|
||||
|
||||
</services>
|
||||
</container>
|
@ -205,9 +205,15 @@
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:complexType name="cache">
|
||||
<xsd:choice minOccurs="1" maxOccurs="unbounded">
|
||||
<xsd:element name="pool" type="cache_pool" />
|
||||
</xsd:choice>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="app" type="xsd:string" minOccurs="0" maxOccurs="1" />
|
||||
<xsd:element name="system" type="xsd:string" minOccurs="0" maxOccurs="1" />
|
||||
<xsd:element name="directory" type="xsd:string" minOccurs="0" maxOccurs="1" />
|
||||
<xsd:element name="default-doctrine-provider" type="xsd:string" minOccurs="0" maxOccurs="1" />
|
||||
<xsd:element name="default-psr6-provider" type="xsd:string" minOccurs="0" maxOccurs="1" />
|
||||
<xsd:element name="default-redis-provider" type="xsd:string" minOccurs="0" maxOccurs="1" />
|
||||
<xsd:element name="pool" type="cache_pool" minOccurs="0" maxOccurs="unbounded" />
|
||||
</xsd:sequence>
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:complexType name="cache_pool">
|
||||
|
@ -29,7 +29,7 @@
|
||||
<service id="validator.mapping.class_metadata_factory" alias="validator" public="false" />
|
||||
|
||||
<service id="validator.mapping.cache.symfony" class="Symfony\Component\Validator\Mapping\Cache\Psr6Cache" public="false">
|
||||
<argument type="service" id="cache.pool.validator" />
|
||||
<argument type="service" id="cache.validator" />
|
||||
</service>
|
||||
|
||||
<service id="validator.mapping.cache.doctrine.apc" class="Symfony\Component\Validator\Mapping\Cache\DoctrineCache" public="false">
|
||||
|
@ -268,6 +268,10 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
|
||||
),
|
||||
'cache' => array(
|
||||
'pools' => array(),
|
||||
'app' => 'cache.adapter.filesystem',
|
||||
'system' => 'cache.adapter.filesystem',
|
||||
'directory' => '%kernel.cache_dir%/pools',
|
||||
'default_redis_provider' => 'redis://localhost',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -3,25 +3,25 @@
|
||||
$container->loadFromExtension('framework', array(
|
||||
'cache' => array(
|
||||
'pools' => array(
|
||||
'foo' => array(
|
||||
'cache.foo' => array(
|
||||
'adapter' => 'cache.adapter.apcu',
|
||||
'default_lifetime' => 30,
|
||||
),
|
||||
'bar' => array(
|
||||
'cache.bar' => array(
|
||||
'adapter' => 'cache.adapter.doctrine',
|
||||
'default_lifetime' => 5,
|
||||
'provider' => 'app.doctrine_cache_provider',
|
||||
),
|
||||
'baz' => array(
|
||||
'cache.baz' => array(
|
||||
'adapter' => 'cache.adapter.filesystem',
|
||||
'default_lifetime' => 7,
|
||||
),
|
||||
'foobar' => array(
|
||||
'cache.foobar' => array(
|
||||
'adapter' => 'cache.adapter.psr6',
|
||||
'default_lifetime' => 10,
|
||||
'provider' => 'app.cache_pool',
|
||||
),
|
||||
'def' => array(
|
||||
'cache.def' => array(
|
||||
'default_lifetime' => 11,
|
||||
),
|
||||
),
|
||||
|
@ -7,11 +7,11 @@
|
||||
|
||||
<framework:config>
|
||||
<framework:cache>
|
||||
<framework:pool name="foo" adapter="cache.adapter.apcu" default-lifetime="30" />
|
||||
<framework:pool name="bar" adapter="cache.adapter.doctrine" default-lifetime="5" provider="app.doctrine_cache_provider" />
|
||||
<framework:pool name="baz" adapter="cache.adapter.filesystem" default-lifetime="7" />
|
||||
<framework:pool name="foobar" adapter="cache.adapter.psr6" default-lifetime="10" provider="app.cache_pool" />
|
||||
<framework:pool name="def" default-lifetime="11" />
|
||||
<framework:pool name="cache.foo" adapter="cache.adapter.apcu" default-lifetime="30" />
|
||||
<framework:pool name="cache.bar" adapter="cache.adapter.doctrine" default-lifetime="5" provider="app.doctrine_cache_provider" />
|
||||
<framework:pool name="cache.baz" adapter="cache.adapter.filesystem" default-lifetime="7" />
|
||||
<framework:pool name="cache.foobar" adapter="cache.adapter.psr6" default-lifetime="10" provider="app.cache_pool" />
|
||||
<framework:pool name="cache.def" default-lifetime="11" />
|
||||
</framework:cache>
|
||||
</framework:config>
|
||||
</container>
|
||||
|
@ -1,19 +1,19 @@
|
||||
framework:
|
||||
cache:
|
||||
pools:
|
||||
foo:
|
||||
cache.foo:
|
||||
adapter: cache.adapter.apcu
|
||||
default_lifetime: 30
|
||||
bar:
|
||||
cache.bar:
|
||||
adapter: cache.adapter.doctrine
|
||||
default_lifetime: 5
|
||||
provider: app.doctrine_cache_provider
|
||||
baz:
|
||||
cache.baz:
|
||||
adapter: cache.adapter.filesystem
|
||||
default_lifetime: 7
|
||||
foobar:
|
||||
cache.foobar:
|
||||
adapter: cache.adapter.psr6
|
||||
default_lifetime: 10
|
||||
provider: app.cache_pool
|
||||
def:
|
||||
cache.def:
|
||||
default_lifetime: 11
|
||||
|
@ -16,6 +16,8 @@ use Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension;
|
||||
use Symfony\Component\Cache\Adapter\ApcuAdapter;
|
||||
use Symfony\Component\Cache\Adapter\DoctrineAdapter;
|
||||
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
|
||||
use Symfony\Component\Cache\Adapter\ProxyAdapter;
|
||||
use Symfony\Component\Cache\Adapter\RedisAdapter;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\DefinitionDecorator;
|
||||
use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
|
||||
@ -619,11 +621,11 @@ abstract class FrameworkExtensionTest extends TestCase
|
||||
{
|
||||
$container = $this->createContainerFromFile('cache');
|
||||
|
||||
$this->assertCachePoolServiceDefinitionIsCreated($container, 'foo', 'cache.adapter.apcu', 30);
|
||||
$this->assertCachePoolServiceDefinitionIsCreated($container, 'bar', 'cache.adapter.doctrine', 5);
|
||||
$this->assertCachePoolServiceDefinitionIsCreated($container, 'baz', 'cache.adapter.filesystem', 7);
|
||||
$this->assertCachePoolServiceDefinitionIsCreated($container, 'foobar', 'cache.adapter.psr6', 10);
|
||||
$this->assertCachePoolServiceDefinitionIsCreated($container, 'def', 'cache.adapter.filesystem', 11);
|
||||
$this->assertCachePoolServiceDefinitionIsCreated($container, 'cache.foo', 'cache.adapter.apcu', 30);
|
||||
$this->assertCachePoolServiceDefinitionIsCreated($container, 'cache.bar', 'cache.adapter.doctrine', 5);
|
||||
$this->assertCachePoolServiceDefinitionIsCreated($container, 'cache.baz', 'cache.adapter.filesystem', 7);
|
||||
$this->assertCachePoolServiceDefinitionIsCreated($container, 'cache.foobar', 'cache.adapter.psr6', 10);
|
||||
$this->assertCachePoolServiceDefinitionIsCreated($container, 'cache.def', 'cache.app', 11);
|
||||
}
|
||||
|
||||
protected function createContainer(array $data = array())
|
||||
@ -697,15 +699,13 @@ abstract class FrameworkExtensionTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
private function assertCachePoolServiceDefinitionIsCreated(ContainerBuilder $container, $name, $adapter, $defaultLifetime)
|
||||
private function assertCachePoolServiceDefinitionIsCreated(ContainerBuilder $container, $id, $adapter, $defaultLifetime)
|
||||
{
|
||||
$id = 'cache.pool.'.$name;
|
||||
|
||||
$this->assertTrue($container->has($id), sprintf('Service definition "%s" for cache pool of type "%s" is registered', $id, $adapter));
|
||||
|
||||
$poolDefinition = $container->getDefinition($id);
|
||||
|
||||
$this->assertInstanceOf(DefinitionDecorator::class, $poolDefinition, sprintf('Cache pool "%s" is based on an abstract cache pool.', $name));
|
||||
$this->assertInstanceOf(DefinitionDecorator::class, $poolDefinition, sprintf('Cache pool "%s" is based on an abstract cache pool.', $id));
|
||||
|
||||
$this->assertTrue($poolDefinition->hasTag('cache.pool'), sprintf('Service definition "%s" is tagged with the "cache.pool" tag.', $id));
|
||||
$this->assertFalse($poolDefinition->isAbstract(), sprintf('Service definition "%s" is not abstract.', $id));
|
||||
@ -714,21 +714,31 @@ abstract class FrameworkExtensionTest extends TestCase
|
||||
$this->assertTrue(isset($tag[0]['default_lifetime']), 'The default lifetime is stored as an attribute of the "cache.pool" tag.');
|
||||
$this->assertSame($defaultLifetime, $tag[0]['default_lifetime'], 'The default lifetime is stored as an attribute of the "cache.pool" tag.');
|
||||
|
||||
$adapterId = $poolDefinition->getParent();
|
||||
$adapterDefinition = $container->findDefinition($adapterId);
|
||||
$parentDefinition = $poolDefinition;
|
||||
do {
|
||||
$parentId = $parentDefinition->getParent();
|
||||
$parentDefinition = $container->findDefinition($parentId);
|
||||
} while ($parentDefinition instanceof DefinitionDecorator);
|
||||
|
||||
switch ($adapter) {
|
||||
case 'cache.adapter.apcu':
|
||||
$this->assertSame(ApcuAdapter::class, $adapterDefinition->getClass());
|
||||
$this->assertSame(ApcuAdapter::class, $parentDefinition->getClass());
|
||||
break;
|
||||
case 'cache.adapter.doctrine':
|
||||
$this->assertSame(DoctrineAdapter::class, $adapterDefinition->getClass());
|
||||
$this->assertSame(DoctrineAdapter::class, $parentDefinition->getClass());
|
||||
break;
|
||||
case 'cache.app':
|
||||
case 'cache.adapter.filesystem':
|
||||
$this->assertSame(FilesystemAdapter::class, $adapterDefinition->getClass());
|
||||
$this->assertSame(FilesystemAdapter::class, $parentDefinition->getClass());
|
||||
break;
|
||||
case 'cache.adapter.psr6':
|
||||
$this->assertSame(ProxyAdapter::class, $parentDefinition->getClass());
|
||||
break;
|
||||
case 'cache.adapter.redis':
|
||||
$this->assertSame(RedisAdapter::class, $parentDefinition->getClass());
|
||||
break;
|
||||
default:
|
||||
$this->fail('Unresolved adapter: '.$adapter);
|
||||
}
|
||||
|
||||
$this->assertTrue($adapterDefinition->isAbstract(), sprintf('Service definition "%s" is abstract.', $adapterId));
|
||||
}
|
||||
}
|
||||
|
@ -36,12 +36,27 @@ class CachePoolsTest extends WebTestCase
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires extension redis
|
||||
*/
|
||||
public function testRedisCustomCachePools()
|
||||
{
|
||||
try {
|
||||
$this->doTestCachePools(array('root_config' => 'redis_custom_config.yml', 'environment' => 'custom_redis_cache'), RedisAdapter::class);
|
||||
} catch (\PHPUnit_Framework_Error_Warning $e) {
|
||||
if (0 !== strpos($e->getMessage(), 'unable to connect to 127.0.0.1')) {
|
||||
throw $e;
|
||||
}
|
||||
$this->markTestSkipped($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function doTestCachePools($options, $adapterClass)
|
||||
{
|
||||
static::bootKernel($options);
|
||||
$container = static::$kernel->getContainer();
|
||||
|
||||
$pool = $container->get('cache.pool.test');
|
||||
$pool = $container->get('cache.test');
|
||||
$this->assertInstanceOf($adapterClass, $pool);
|
||||
|
||||
$key = 'foobar';
|
||||
|
@ -4,5 +4,5 @@ imports:
|
||||
framework:
|
||||
cache:
|
||||
pools:
|
||||
test:
|
||||
cache.test:
|
||||
public: true
|
||||
|
@ -1,22 +1,9 @@
|
||||
imports:
|
||||
- { resource: ../config/default.yml }
|
||||
|
||||
services:
|
||||
cache.adapter.redis.connection:
|
||||
public: false
|
||||
class: Redis
|
||||
calls:
|
||||
- [connect, [127.0.0.1]]
|
||||
|
||||
cache.adapter.shared:
|
||||
abstract: true
|
||||
parent: cache.adapter.redis
|
||||
tags:
|
||||
- name: cache.pool
|
||||
provider: cache.adapter.redis.connection
|
||||
|
||||
framework:
|
||||
cache:
|
||||
app: cache.adapter.redis
|
||||
pools:
|
||||
test:
|
||||
cache.test:
|
||||
public: true
|
||||
|
@ -0,0 +1,21 @@
|
||||
imports:
|
||||
- { resource: ../config/default.yml }
|
||||
|
||||
services:
|
||||
cache.test_redis_connection:
|
||||
public: false
|
||||
class: Redis
|
||||
calls:
|
||||
- [connect, [127.0.0.1]]
|
||||
|
||||
cache.app:
|
||||
parent: cache.adapter.redis
|
||||
tags:
|
||||
- name: cache.pool
|
||||
provider: cache.test_redis_connection
|
||||
|
||||
framework:
|
||||
cache:
|
||||
pools:
|
||||
cache.test:
|
||||
public: true
|
Reference in New Issue
Block a user