Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit88f22a2

Browse files
[FrameworkBundle] Allow configuring taggable cache pools
1 parent782ffe2 commit88f22a2

File tree

8 files changed

+97
-11
lines changed

8 files changed

+97
-11
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ public function process(ContainerBuilder $container)
3131
foreach ($container->findTaggedServiceIds('cache.pool.clearer')as$id =>$attr) {
3232
$clearer =$container->getDefinition($id);
3333
$pools =array();
34-
foreach ($clearer->getArgument(0)as$id =>$ref) {
35-
if ($container->hasDefinition($id)) {
36-
$pools[$id] =newReference($id);
34+
foreach ($clearer->getArgument(0)as$name =>$ref) {
35+
if ($container->hasDefinition($id = (string)$ref)) {
36+
$pools[$name] =newReference($id);
3737
}
3838
}
3939
$clearer->replaceArgument(0,$pools);

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public function process(ContainerBuilder $container)
4141
$clearers =array();
4242
$attributes =array(
4343
'provider',
44+
'name',
4445
'namespace',
4546
'default_lifetime',
4647
'reset',
@@ -56,8 +57,9 @@ public function process(ContainerBuilder $container)
5657
$tags[0] +=$t[0];
5758
}
5859
}
60+
$name =$tags[0]['name'] ??$id;
5961
if (!isset($tags[0]['namespace'])) {
60-
$tags[0]['namespace'] =$this->getNamespace($seed,$id);
62+
$tags[0]['namespace'] =$this->getNamespace($seed,$name);
6163
}
6264
if (isset($tags[0]['clearer'])) {
6365
$clearer =$tags[0]['clearer'];
@@ -67,7 +69,7 @@ public function process(ContainerBuilder $container)
6769
}else {
6870
$clearer =null;
6971
}
70-
unset($tags[0]['clearer']);
72+
unset($tags[0]['clearer'],$tags[0]['name']);
7173

7274
if (isset($tags[0]['provider'])) {
7375
$tags[0]['provider'] =newReference(static::getServiceProvider($container,$tags[0]['provider']));
@@ -86,14 +88,14 @@ public function process(ContainerBuilder $container)
8688
unset($tags[0][$attr]);
8789
}
8890
if (!empty($tags[0])) {
89-
thrownewInvalidArgumentException(sprintf('Invalid "cache.pool" tag for service "%s": accepted attributes are "clearer", "provider", "namespace", "default_lifetime" and "reset", found "%s".',$id,implode('", "',array_keys($tags[0]))));
91+
thrownewInvalidArgumentException(sprintf('Invalid "cache.pool" tag for service "%s": accepted attributes are "clearer", "provider", "name", "namespace", "default_lifetime" and "reset", found "%s".',$id,implode('", "',array_keys($tags[0]))));
9092
}
9193

9294
if (null !==$clearer) {
93-
$clearers[$clearer][$id] =newReference($id,$container::IGNORE_ON_UNINITIALIZED_REFERENCE);
95+
$clearers[$clearer][$name] =newReference($id,$container::IGNORE_ON_UNINITIALIZED_REFERENCE);
9496
}
9597

96-
$pools[$id] =newReference($id,$container::IGNORE_ON_UNINITIALIZED_REFERENCE);
98+
$pools[$name] =newReference($id,$container::IGNORE_ON_UNINITIALIZED_REFERENCE);
9799
}
98100

99101
$clearer ='cache.global_clearer';

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,7 @@ private function addCacheSection(ArrayNodeDefinition $rootNode)
861861
->prototype('array')
862862
->children()
863863
->scalarNode('adapter')->defaultValue('cache.app')->end()
864+
->scalarNode('tags')->defaultNull()->end()
864865
->booleanNode('public')->defaultFalse()->end()
865866
->integerNode('default_lifetime')->end()
866867
->scalarNode('provider')

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
useSymfony\Component\Cache\Adapter\AbstractAdapter;
2323
useSymfony\Component\Cache\Adapter\AdapterInterface;
2424
useSymfony\Component\Cache\Adapter\ArrayAdapter;
25+
useSymfony\Component\Cache\Adapter\TagAwareAdapter;
2526
useSymfony\Component\Cache\ResettableInterface;
2627
useSymfony\Component\Config\FileLocator;
2728
useSymfony\Component\Config\Loader\LoaderInterface;
@@ -1511,12 +1512,31 @@ private function registerCacheConfiguration(array $config, ContainerBuilder $con
15111512
$config['pools']['cache.'.$name] =array(
15121513
'adapter' =>$config[$name],
15131514
'public' =>true,
1515+
'tags' =>false,
15141516
);
15151517
}
15161518
foreach ($config['pools']as$name =>$pool) {
1519+
if ($config['pools'][$pool['adapter']]['tags'] ??false) {
1520+
$pool['adapter'] ='.'.$pool['adapter'].'.inner';
1521+
}
15171522
$definition =newChildDefinition($pool['adapter']);
1523+
1524+
if ($pool['tags']) {
1525+
if ($config['pools'][$pool['tags']]['tags'] ??false) {
1526+
$pool['tags'] ='.'.$pool['tags'].'.inner';
1527+
}
1528+
$container->register($name, TagAwareAdapter::class)
1529+
->addArgument(newReference('.'.$name.'.inner'))
1530+
->addArgument(true !==$pool['tags'] ?newReference($pool['tags']) :null)
1531+
->setPublic($pool['public'])
1532+
;
1533+
1534+
$pool['name'] =$name;
1535+
$pool['public'] =false;
1536+
$name ='.'.$name.'.inner';
1537+
}
15181538
$definition->setPublic($pool['public']);
1519-
unset($pool['adapter'],$pool['public']);
1539+
unset($pool['adapter'],$pool['public'],$pool['tags']);
15201540

15211541
$definition->addTag('cache.pool',$pool);
15221542
$container->setDefinition($name,$definition);

‎src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/CachePoolClearerPassTest.php‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ public function testPoolRefsAreWeak()
3939
$publicPool->addTag('cache.pool',array('clearer' =>'clearer_alias'));
4040
$container->setDefinition('public.pool',$publicPool);
4141

42+
$publicPool =newDefinition();
43+
$publicPool->addArgument('namespace');
44+
$publicPool->addTag('cache.pool',array('clearer' =>'clearer_alias','name' =>'pool2'));
45+
$container->setDefinition('public.pool2',$publicPool);
46+
4247
$privatePool =newDefinition();
4348
$privatePool->setPublic(false);
4449
$privatePool->addArgument('namespace');
@@ -55,7 +60,11 @@ public function testPoolRefsAreWeak()
5560
$pass->process($container);
5661
}
5762

58-
$this->assertEquals(array(array('public.pool' =>newReference('public.pool'))),$clearer->getArguments());
59-
$this->assertEquals(array(array('public.pool' =>newReference('public.pool'))),$globalClearer->getArguments());
63+
$expected =array(array(
64+
'public.pool' =>newReference('public.pool'),
65+
'pool2' =>newReference('public.pool2'),
66+
));
67+
$this->assertEquals($expected,$clearer->getArguments());
68+
$this->assertEquals($expected,$globalClearer->getArguments());
6069
}
6170
}

‎src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/CachePoolPassTest.php‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,28 @@ public function testArgsAreReplaced()
9393
$this->assertSame(3,$cachePool->getArgument(2));
9494
}
9595

96+
publicfunctiontestWithNameAttribute()
97+
{
98+
$container =newContainerBuilder();
99+
$container->setParameter('kernel.debug',false);
100+
$container->setParameter('kernel.name','app');
101+
$container->setParameter('kernel.environment','prod');
102+
$container->setParameter('cache.prefix.seed','foo');
103+
$cachePool =newDefinition();
104+
$cachePool->addTag('cache.pool',array(
105+
'name' =>'foobar',
106+
'provider' =>'foobar',
107+
));
108+
$cachePool->addArgument(null);
109+
$cachePool->addArgument(null);
110+
$cachePool->addArgument(null);
111+
$container->setDefinition('app.cache_pool',$cachePool);
112+
113+
$this->cachePoolPass->process($container);
114+
115+
$this->assertSame('9HvPgAayyh',$cachePool->getArgument(1));
116+
}
117+
96118
/**
97119
* @expectedException \InvalidArgumentException
98120
* @expectedExceptionMessage Invalid "cache.pool" tag for service "app.cache_pool": accepted attributes are

‎src/Symfony/Bundle/FrameworkBundle/Tests/Functional/CachePoolsTest.php‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
useSymfony\Component\Cache\Adapter\AdapterInterface;
1515
useSymfony\Component\Cache\Adapter\RedisAdapter;
16+
useSymfony\Component\Cache\Adapter\TagAwareAdapter;
1617
useSymfony\Component\Cache\Exception\InvalidArgumentException;
1718

1819
class CachePoolsTestextends WebTestCase
@@ -94,6 +95,25 @@ private function doTestCachePools($options, $adapterClass)
9495

9596
$item =$pool2->getItem($key);
9697
$this->assertTrue($item->isHit());
98+
99+
$prefix ="\0".TagAwareAdapter::class."\0";
100+
$pool4 =$container->get('cache.pool4');
101+
$this->assertInstanceof(TagAwareAdapter::class,$pool4);
102+
$pool4 = (array)$pool4;
103+
$this->assertSame($pool4[$prefix.'pool'],$pool4[$prefix.'tags']);
104+
105+
$pool5 =$container->get('cache.pool5');
106+
$this->assertInstanceof(TagAwareAdapter::class,$pool5);
107+
$pool5 = (array)$pool5;
108+
$this->assertSame($pool2,$pool5[$prefix.'tags']);
109+
110+
$pool6 =$container->get('cache.pool6');
111+
$this->assertInstanceof(TagAwareAdapter::class,$pool6);
112+
$pool6 = (array)$pool6;
113+
$this->assertSame($pool4[$prefix.'pool'],$pool6[$prefix.'tags']);
114+
115+
$pool7 =$container->get('cache.pool7');
116+
$this->assertNotInstanceof(TagAwareAdapter::class,$pool7);
97117
}
98118

99119
protectedstaticfunctioncreateKernel(array$options =array())

‎src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/CachePools/config.yml‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,15 @@ framework:
1212
adapter:cache.pool3
1313
cache.pool3:
1414
clearer:~
15+
cache.pool4:
16+
tags:true
17+
public:true
18+
cache.pool5:
19+
tags:cache.pool2
20+
public:true
21+
cache.pool6:
22+
tags:cache.pool4
23+
public:true
24+
cache.pool7:
25+
adapter:cache.pool4
26+
public:true

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp