Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 788080b

Browse filesBrowse files
[FrameworkBundle] Add & use Psr6CacheClearer
1 parent a6bb17f commit 788080b
Copy full SHA for 788080b

File tree

10 files changed

+132
-7
lines changed
Filter options

10 files changed

+132
-7
lines changed

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CachePoolPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CachePoolPass.php
+12-1Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,30 @@ public function process(ContainerBuilder $container)
4545
if ($pool->isAbstract()) {
4646
continue;
4747
}
48+
if (isset($tags[0]['clearer_service'])) {
49+
$clearer = $container->getDefinition($tags[0]['clearer_service']);
50+
} else {
51+
$clearer = null;
52+
}
53+
unset($tags[0]['clearer_service']);
54+
4855
if (isset($tags[0]['provider_service']) && is_string($tags[0]['provider_service'])) {
4956
$tags[0]['provider_service'] = new Reference($tags[0]['provider_service']);
5057
}
5158
$i = 0;
5259
foreach ($attributes as $attr) {
5360
if (isset($tags[0][$attr])) {
5461
$pool->replaceArgument($i++, $tags[0][$attr]);
55-
unset($tags[0][$attr]);
5662
}
63+
unset($tags[0][$attr]);
5764
}
5865
if (!empty($tags[0])) {
5966
throw new \InvalidArgumentException(sprintf('Invalid "cache.pool" tag for service "%s": accepted attributes are "provider_service", "namespace", "default_lifetime" and "directory", found "%s".', $id, implode('", "', array_keys($tags[0]))));
6067
}
68+
69+
if (null !== $clearer) {
70+
$clearer->addMethodCall('addPool', array(new Reference($id)));
71+
}
6172
}
6273
}
6374

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,7 @@ private function addCacheSection(ArrayNodeDefinition $rootNode)
569569
->integerNode('default_lifetime')->defaultNull()->end()
570570
->scalarNode('provider_service')->defaultNull()->end()
571571
->scalarNode('directory')->defaultNull()->end()
572+
->scalarNode('clearer_service')->defaultValue('cache.default_pools_clearer')->end()
572573
->end()
573574
->end()
574575
->end()

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/cache_pools.xml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Resources/config/cache_pools.xml
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
<services>
88

9+
<service id="cache.default_pools_clearer" class="Symfony\Component\HttpKernel\CacheClearer\Psr6CacheClearer" public="false">
10+
<tag name="kernel.cache_clearer" />
11+
</service>
12+
913
<service id="cache.adapter.default" alias="cache.adapter.filesystem" />
1014

1115
<service id="cache.adapter.apcu" class="Symfony\Component\Cache\Adapter\ApcuAdapter" abstract="true">
+45Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional;
13+
14+
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
15+
16+
class CachePoolsTest extends WebTestCase
17+
{
18+
public function testCachePools()
19+
{
20+
static::bootKernel();
21+
$container = static::$kernel->getContainer();
22+
23+
$pool = $container->get('cache.pool.test');
24+
$this->assertInstanceOf(FilesystemAdapter::class, $pool);
25+
26+
$key = 'foobar';
27+
$pool->deleteItem($key);
28+
$item = $pool->getItem($key);
29+
$this->assertFalse($item->isHit());
30+
31+
$item->set('baz');
32+
$pool->save($item);
33+
$item = $pool->getItem($key);
34+
$this->assertTrue($item->isHit());
35+
36+
$container->get('cache_clearer')->clear($container->getParameter('kernel.cache_dir'));
37+
$item = $pool->getItem($key);
38+
$this->assertFalse($item->isHit());
39+
}
40+
41+
protected static function createKernel(array $options = array())
42+
{
43+
return parent::createKernel(array('test_case' => 'CachePools') + $options);
44+
}
45+
}
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestBundle;
13+
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
14+
15+
return array(
16+
new FrameworkBundle(),
17+
new TestBundle(),
18+
);
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
imports:
2+
- { resource: ../config/default.yml }
3+
4+
framework:
5+
cache:
6+
pools:
7+
test:
8+
public: true

‎src/Symfony/Bundle/FrameworkBundle/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/composer.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"php": ">=5.5.9",
2020
"symfony/asset": "~2.8|~3.0",
2121
"symfony/class-loader": "~2.8|~3.0",
22-
"symfony/dependency-injection": "~2.8|~3.0",
22+
"symfony/dependency-injection": "~3.1",
2323
"symfony/config": "~2.8|~3.0",
2424
"symfony/event-dispatcher": "~2.8|~3.0",
2525
"symfony/http-foundation": "~3.1",

‎src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ public function __construct()
5757
);
5858

5959
$this->removingPasses = array(
60+
new ReplaceAliasByActualDefinitionPass(),
6061
new RemovePrivateAliasesPass(),
6162
new RemoveAbstractDefinitionsPass(),
62-
new ReplaceAliasByActualDefinitionPass(),
6363
new RepeatedPass(array(
6464
new AnalyzeServiceReferencesPass(),
6565
new InlineServiceDefinitionsPass(),
@@ -102,8 +102,7 @@ public function addPass(CompilerPassInterface $pass, $type = self::TYPE_BEFORE_O
102102
throw new InvalidArgumentException(sprintf('Invalid type "%s".', $type));
103103
}
104104

105-
$passes = &$this->$property;
106-
$passes[] = $pass;
105+
$this->{$property}[] = $pass;
107106
}
108107

109108
/**

‎src/Symfony/Component/DependencyInjection/Compiler/ResolveDefinitionTemplatesPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/ResolveDefinitionTemplatesPass.php
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\DependencyInjection\DefinitionDecorator;
1616
use Symfony\Component\DependencyInjection\ContainerBuilder;
1717
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
18+
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
1819

1920
/**
2021
* This replaces all DefinitionDecorator instances with their equivalent fully
@@ -96,11 +97,12 @@ private function resolveArguments(ContainerBuilder $container, array $arguments,
9697
*/
9798
private function resolveDefinition(ContainerBuilder $container, DefinitionDecorator $definition)
9899
{
99-
if (!$container->hasDefinition($parent = $definition->getParent())) {
100+
try {
101+
$parentDef = $container->findDefinition($parent = $definition->getParent());
102+
} catch (ServiceNotFoundException $e) {
100103
throw new RuntimeException(sprintf('The parent definition "%s" defined for definition "%s" does not exist.', $parent, $this->currentId));
101104
}
102105

103-
$parentDef = $container->getDefinition($parent);
104106
if ($parentDef instanceof DefinitionDecorator) {
105107
$id = $this->currentId;
106108
$this->currentId = $parent;
+37Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\HttpKernel\CacheClearer;
13+
14+
use Psr\Cache\CacheItemPoolInterface;
15+
16+
/**
17+
* @author Nicolas Grekas <p@tchwork.com>
18+
*/
19+
class Psr6CacheClearer implements CacheClearerInterface
20+
{
21+
private $pools = array();
22+
23+
public function addPool(CacheItemPoolInterface $pool)
24+
{
25+
$this->pools[] = $pool;
26+
}
27+
28+
/**
29+
* {@inheritdoc}
30+
*/
31+
public function clear($cacheDir)
32+
{
33+
foreach ($this->pools as $pool) {
34+
$pool->clear();
35+
}
36+
}
37+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.