[FrameworkBundle] Add default pool & system adapter
This commit is contained in:
parent
714b916d5d
commit
41526342ea
@ -63,7 +63,7 @@ class CachePoolPass implements CompilerPassInterface
|
||||
unset($tags[0][$attr]);
|
||||
}
|
||||
if (!empty($tags[0])) {
|
||||
throw new \InvalidArgumentException(sprintf('Invalid "cache.pool" tag for service "%s": accepted attributes are "provider", "namespace" and "default_lifetime", found "%s".', $id, implode('", "', array_keys($tags[0]))));
|
||||
throw new \InvalidArgumentException(sprintf('Invalid "cache.pool" tag for service "%s": accepted attributes are "clearer", "provider", "namespace" and "default_lifetime", found "%s".', $id, implode('", "', array_keys($tags[0]))));
|
||||
}
|
||||
|
||||
if (null !== $clearer) {
|
||||
|
@ -555,6 +555,7 @@ class Configuration implements ConfigurationInterface
|
||||
->children()
|
||||
->arrayNode('cache')
|
||||
->info('Cache configuration')
|
||||
->addDefaultsIfNotSet()
|
||||
->fixXmlConfig('pool')
|
||||
->children()
|
||||
->arrayNode('pools')
|
||||
@ -563,7 +564,7 @@ class Configuration implements ConfigurationInterface
|
||||
->children()
|
||||
->scalarNode('adapter')
|
||||
->info('The cache pool adapter service to use as template definition.')
|
||||
->defaultValue('cache.adapter.default')
|
||||
->defaultValue('cache.adapter.shared')
|
||||
->end()
|
||||
->booleanNode('public')->defaultFalse()->end()
|
||||
->integerNode('default_lifetime')->end()
|
||||
|
@ -122,6 +122,7 @@ class FrameworkExtension extends Extension
|
||||
$this->registerFragmentsConfiguration($config['fragments'], $container, $loader);
|
||||
$this->registerTranslatorConfiguration($config['translator'], $container);
|
||||
$this->registerProfilerConfiguration($config['profiler'], $container, $loader);
|
||||
$this->registerCacheConfiguration($config['cache'], $container, $loader);
|
||||
|
||||
if ($this->isConfigEnabled($container, $config['router'])) {
|
||||
$this->registerRouterConfiguration($config['router'], $container, $loader);
|
||||
@ -138,10 +139,6 @@ class FrameworkExtension extends Extension
|
||||
$this->registerPropertyInfoConfiguration($config['property_info'], $container, $loader);
|
||||
}
|
||||
|
||||
if (isset($config['cache'])) {
|
||||
$this->registerCacheConfiguration($config['cache'], $container, $loader);
|
||||
}
|
||||
|
||||
$loader->load('debug_prod.xml');
|
||||
$definition = $container->findDefinition('debug.debug_handlers_listener');
|
||||
|
||||
@ -1022,9 +1019,7 @@ class FrameworkExtension extends Extension
|
||||
|
||||
private function registerCacheConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
|
||||
{
|
||||
if (!empty($config['pools'])) {
|
||||
$loader->load('cache_pools.xml');
|
||||
}
|
||||
$loader->load('cache_pools.xml');
|
||||
|
||||
foreach ($config['pools'] as $name => $poolConfig) {
|
||||
$poolDefinition = new DefinitionDecorator($poolConfig['adapter']);
|
||||
@ -1034,6 +1029,14 @@ class FrameworkExtension extends Extension
|
||||
$poolDefinition->addTag('cache.pool', $poolConfig);
|
||||
$container->setDefinition('cache.pool.'.$name, $poolDefinition);
|
||||
}
|
||||
|
||||
$this->addClassesToCompile(array(
|
||||
'Psr\Cache\CacheItemInterface',
|
||||
'Psr\Cache\CacheItemPoolInterface',
|
||||
'Symfony\Component\Cache\Adapter\AdapterInterface',
|
||||
'Symfony\Component\Cache\Adapter\AbstractAdapter',
|
||||
'Symfony\Component\Cache\CacheItem',
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -10,7 +10,16 @@
|
||||
<tag name="kernel.cache_clearer" />
|
||||
</service>
|
||||
|
||||
<service id="cache.adapter.default" alias="cache.adapter.filesystem" />
|
||||
<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>
|
||||
|
||||
<service id="cache.pool.local" parent="cache.adapter.local">
|
||||
<tag name="cache.pool" clearer="cache.default_pools_clearer" />
|
||||
</service>
|
||||
|
||||
<service id="cache.adapter.apcu" class="Symfony\Component\Cache\Adapter\ApcuAdapter" abstract="true">
|
||||
<argument /> <!-- namespace -->
|
||||
|
@ -216,7 +216,6 @@
|
||||
<xsd:attribute name="public" type="xsd:boolean" />
|
||||
<xsd:attribute name="default-lifetime" type="xsd:integer" />
|
||||
<xsd:attribute name="provider" type="xsd:string" />
|
||||
<xsd:attribute name="directory" type="xsd:string" />
|
||||
<xsd:attribute name="clearer" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:schema>
|
||||
|
@ -265,6 +265,9 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
|
||||
'base_urls' => array(),
|
||||
'packages' => array(),
|
||||
),
|
||||
'cache' => array(
|
||||
'pools' => array(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ services:
|
||||
calls:
|
||||
- [connect, [127.0.0.1]]
|
||||
|
||||
cache.adapter.default:
|
||||
cache.adapter.shared:
|
||||
abstract: true
|
||||
parent: cache.adapter.redis
|
||||
tags:
|
||||
|
@ -18,6 +18,7 @@
|
||||
"require": {
|
||||
"php": ">=5.5.9",
|
||||
"symfony/asset": "~2.8|~3.0",
|
||||
"symfony/cache": "~3.1",
|
||||
"symfony/class-loader": "~2.8|~3.0",
|
||||
"symfony/dependency-injection": "~3.1",
|
||||
"symfony/config": "~2.8|~3.0",
|
||||
@ -38,7 +39,6 @@
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony/browser-kit": "~2.8|~3.0",
|
||||
"symfony/cache": "~3.1",
|
||||
"symfony/console": "~2.8|~3.0",
|
||||
"symfony/css-selector": "~2.8|~3.0",
|
||||
"symfony/dom-crawler": "~2.8|~3.0",
|
||||
|
@ -37,7 +37,6 @@ class RedisAdapterTest extends CachePoolTest
|
||||
$e = error_get_last();
|
||||
self::markTestSkipped($e['message']);
|
||||
}
|
||||
self::$redis->select(1993);
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
|
@ -15,7 +15,6 @@ use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\DefinitionDecorator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
||||
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
|
||||
|
||||
/**
|
||||
* This replaces all DefinitionDecorator instances with their equivalent fully
|
||||
@ -97,12 +96,11 @@ class ResolveDefinitionTemplatesPass implements CompilerPassInterface
|
||||
*/
|
||||
private function resolveDefinition(ContainerBuilder $container, DefinitionDecorator $definition)
|
||||
{
|
||||
try {
|
||||
$parentDef = $container->findDefinition($parent = $definition->getParent());
|
||||
} catch (ServiceNotFoundException $e) {
|
||||
if (!$container->has($parent = $definition->getParent())) {
|
||||
throw new RuntimeException(sprintf('The parent definition "%s" defined for definition "%s" does not exist.', $parent, $this->currentId));
|
||||
}
|
||||
|
||||
$parentDef = $container->findDefinition($parent);
|
||||
if ($parentDef instanceof DefinitionDecorator) {
|
||||
$id = $this->currentId;
|
||||
$this->currentId = $parent;
|
||||
|
@ -309,6 +309,20 @@ class ResolveDefinitionTemplatesPassTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals(array('Foo', 'Bar'), $def->getAutowiringTypes());
|
||||
}
|
||||
|
||||
public function testProcessResolvesAliases()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('parent', 'ParentClass');
|
||||
$container->setAlias('parent_alias', 'parent');
|
||||
$container->setDefinition('child', new DefinitionDecorator('parent_alias'));
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$def = $container->getDefinition('child');
|
||||
$this->assertSame('ParentClass', $def->getClass());
|
||||
}
|
||||
|
||||
protected function process(ContainerBuilder $container)
|
||||
{
|
||||
$pass = new ResolveDefinitionTemplatesPass();
|
||||
|
Reference in New Issue
Block a user