Skip to content

Commit a8c5a69

Browse files
[FrameworkBundle] Add default pool & system adapter
1 parent 73aef86 commit a8c5a69

File tree

8 files changed

+28
-13
lines changed

8 files changed

+28
-13
lines changed

DependencyInjection/Compiler/CachePoolPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function process(ContainerBuilder $container)
6363
unset($tags[0][$attr]);
6464
}
6565
if (!empty($tags[0])) {
66-
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]))));
66+
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]))));
6767
}
6868

6969
if (null !== $clearer) {

DependencyInjection/Configuration.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,7 @@ private function addCacheSection(ArrayNodeDefinition $rootNode)
555555
->children()
556556
->arrayNode('cache')
557557
->info('Cache configuration')
558+
->addDefaultsIfNotSet()
558559
->fixXmlConfig('pool')
559560
->children()
560561
->arrayNode('pools')
@@ -563,7 +564,7 @@ private function addCacheSection(ArrayNodeDefinition $rootNode)
563564
->children()
564565
->scalarNode('adapter')
565566
->info('The cache pool adapter service to use as template definition.')
566-
->defaultValue('cache.adapter.default')
567+
->defaultValue('cache.adapter.shared')
567568
->end()
568569
->booleanNode('public')->defaultFalse()->end()
569570
->integerNode('default_lifetime')->end()

DependencyInjection/FrameworkExtension.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ public function load(array $configs, ContainerBuilder $container)
122122
$this->registerFragmentsConfiguration($config['fragments'], $container, $loader);
123123
$this->registerTranslatorConfiguration($config['translator'], $container);
124124
$this->registerProfilerConfiguration($config['profiler'], $container, $loader);
125+
$this->registerCacheConfiguration($config['cache'], $container, $loader);
125126

126127
if ($this->isConfigEnabled($container, $config['router'])) {
127128
$this->registerRouterConfiguration($config['router'], $container, $loader);
@@ -138,10 +139,6 @@ public function load(array $configs, ContainerBuilder $container)
138139
$this->registerPropertyInfoConfiguration($config['property_info'], $container, $loader);
139140
}
140141

141-
if (isset($config['cache'])) {
142-
$this->registerCacheConfiguration($config['cache'], $container, $loader);
143-
}
144-
145142
$loader->load('debug_prod.xml');
146143
$definition = $container->findDefinition('debug.debug_handlers_listener');
147144

@@ -1022,9 +1019,7 @@ private function registerPropertyInfoConfiguration(array $config, ContainerBuild
10221019

10231020
private function registerCacheConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
10241021
{
1025-
if (!empty($config['pools'])) {
1026-
$loader->load('cache_pools.xml');
1027-
}
1022+
$loader->load('cache_pools.xml');
10281023

10291024
foreach ($config['pools'] as $name => $poolConfig) {
10301025
$poolDefinition = new DefinitionDecorator($poolConfig['adapter']);
@@ -1034,6 +1029,14 @@ private function registerCacheConfiguration(array $config, ContainerBuilder $con
10341029
$poolDefinition->addTag('cache.pool', $poolConfig);
10351030
$container->setDefinition('cache.pool.'.$name, $poolDefinition);
10361031
}
1032+
1033+
$this->addClassesToCompile(array(
1034+
'Psr\Cache\CacheItemInterface',
1035+
'Psr\Cache\CacheItemPoolInterface',
1036+
'Symfony\Component\Cache\Adapter\AdapterInterface',
1037+
'Symfony\Component\Cache\Adapter\AbstractAdapter',
1038+
'Symfony\Component\Cache\CacheItem',
1039+
));
10371040
}
10381041

10391042
/**

Resources/config/cache_pools.xml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,16 @@
1010
<tag name="kernel.cache_clearer" />
1111
</service>
1212

13-
<service id="cache.adapter.default" alias="cache.adapter.filesystem" />
13+
<service id="cache.adapter.shared" alias="cache.adapter.filesystem" />
14+
<service id="cache.adapter.local" alias="cache.adapter.filesystem" />
15+
16+
<service id="cache.pool.shared" parent="cache.adapter.shared">
17+
<tag name="cache.pool" clearer="cache.default_pools_clearer" />
18+
</service>
19+
20+
<service id="cache.pool.local" parent="cache.adapter.local">
21+
<tag name="cache.pool" clearer="cache.default_pools_clearer" />
22+
</service>
1423

1524
<service id="cache.adapter.apcu" class="Symfony\Component\Cache\Adapter\ApcuAdapter" abstract="true">
1625
<argument /> <!-- namespace -->

Resources/config/schema/symfony-1.0.xsd

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@
216216
<xsd:attribute name="public" type="xsd:boolean" />
217217
<xsd:attribute name="default-lifetime" type="xsd:integer" />
218218
<xsd:attribute name="provider" type="xsd:string" />
219-
<xsd:attribute name="directory" type="xsd:string" />
220219
<xsd:attribute name="clearer" type="xsd:string" />
221220
</xsd:complexType>
222221
</xsd:schema>

Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,9 @@ protected static function getBundleDefaultConfig()
265265
'base_urls' => array(),
266266
'packages' => array(),
267267
),
268+
'cache' => array(
269+
'pools' => array(),
270+
),
268271
);
269272
}
270273
}

Tests/Functional/app/CachePools/redis_config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ services:
88
calls:
99
- [connect, [127.0.0.1]]
1010

11-
cache.adapter.default:
11+
cache.adapter.shared:
1212
abstract: true
1313
parent: cache.adapter.redis
1414
tags:

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"require": {
1919
"php": ">=5.5.9",
2020
"symfony/asset": "~2.8|~3.0",
21+
"symfony/cache": "~3.1",
2122
"symfony/class-loader": "~2.8|~3.0",
2223
"symfony/dependency-injection": "~3.1",
2324
"symfony/config": "~2.8|~3.0",
@@ -38,7 +39,6 @@
3839
},
3940
"require-dev": {
4041
"symfony/browser-kit": "~2.8|~3.0",
41-
"symfony/cache": "~3.1",
4242
"symfony/console": "~2.8|~3.0",
4343
"symfony/css-selector": "~2.8|~3.0",
4444
"symfony/dom-crawler": "~2.8|~3.0",

0 commit comments

Comments
 (0)