Skip to content

Commit 9efdbf6

Browse files
committed
[HttpKernel] Add arguments for cache passes
1 parent 6c45efa commit 9efdbf6

File tree

6 files changed

+38
-11
lines changed

6 files changed

+38
-11
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddCacheClearerPass.php

+4
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,8 @@
2424
*/
2525
class AddCacheClearerPass extends BaseAddCacheClearerPass
2626
{
27+
public function __construct()
28+
{
29+
parent::__construct('cache_clearer', 'kernel.cache_clearer');
30+
}
2731
}

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddCacheWarmerPass.php

+4
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,8 @@
2424
*/
2525
class AddCacheWarmerPass extends BaseAddCacheWarmerPass
2626
{
27+
public function __construct()
28+
{
29+
parent::__construct('cache_warmer', 'kernel.cache_warmer');
30+
}
2731
}

src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ public function build(ContainerBuilder $container)
8282
$container->addCompilerPass(new FormPass());
8383
$container->addCompilerPass(new TranslatorPass());
8484
$container->addCompilerPass(new LoggingTranslatorPass());
85-
$container->addCompilerPass(new AddCacheWarmerPass());
86-
$container->addCompilerPass(new AddCacheClearerPass());
85+
$container->addCompilerPass(new AddCacheWarmerPass('cache_warmer', 'kernel.cache_warmer'));
86+
$container->addCompilerPass(new AddCacheClearerPass('cache_clearer', 'kernel.cache_clearer'));
8787
$container->addCompilerPass(new AddExpressionLanguageProvidersPass());
8888
$container->addCompilerPass(new TranslationExtractorPass());
8989
$container->addCompilerPass(new TranslationDumperPass());

src/Symfony/Component/HttpKernel/DependencyInjection/AddCacheClearerPass.php

+12-3
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,29 @@
2222
*/
2323
class AddCacheClearerPass implements CompilerPassInterface
2424
{
25+
private $tag;
26+
private $serviceName;
27+
28+
public function __construct($serviceName, $tag)
29+
{
30+
$this->serviceName = $serviceName;
31+
$this->tag = $tag;
32+
}
33+
2534
/**
2635
* {@inheritdoc}
2736
*/
2837
public function process(ContainerBuilder $container)
2938
{
30-
if (!$container->hasDefinition('cache_clearer')) {
39+
if (!$container->hasDefinition($this->serviceName)) {
3140
return;
3241
}
3342

3443
$clearers = array();
35-
foreach ($container->findTaggedServiceIds('kernel.cache_clearer') as $id => $attributes) {
44+
foreach ($container->findTaggedServiceIds($this->tag) as $id => $attributes) {
3645
$clearers[] = new Reference($id);
3746
}
3847

39-
$container->getDefinition('cache_clearer')->replaceArgument(0, $clearers);
48+
$container->getDefinition($this->serviceName)->replaceArgument(0, $clearers);
4049
}
4150
}

src/Symfony/Component/HttpKernel/DependencyInjection/AddCacheWarmerPass.php

+12-3
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,30 @@ class AddCacheWarmerPass implements CompilerPassInterface
2424
{
2525
use PriorityTaggedServiceTrait;
2626

27+
private $tag;
28+
private $serviceName;
29+
30+
public function __construct($serviceName, $tag)
31+
{
32+
$this->serviceName = $serviceName;
33+
$this->tag = $tag;
34+
}
35+
2736
/**
2837
* {@inheritdoc}
2938
*/
3039
public function process(ContainerBuilder $container)
3140
{
32-
if (!$container->hasDefinition('cache_warmer')) {
41+
if (!$container->hasDefinition($this->serviceName)) {
3342
return;
3443
}
3544

36-
$warmers = $this->findAndSortTaggedServices('kernel.cache_warmer', $container);
45+
$warmers = $this->findAndSortTaggedServices($this->tag, $container);
3746

3847
if (empty($warmers)) {
3948
return;
4049
}
4150

42-
$container->getDefinition('cache_warmer')->replaceArgument(0, $warmers);
51+
$container->getDefinition($this->serviceName)->replaceArgument(0, $warmers);
4352
}
4453
}

src/Symfony/Component/HttpKernel/Tests/DependencyInjection/AddCacheWarmerPassTest.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\HttpKernel\Tests\DependencyInjection;
1313

14+
use Symfony\Bridge\PhpUnit\ErrorAssert;
1415
use Symfony\Component\DependencyInjection\Reference;
1516
use Symfony\Component\HttpKernel\DependencyInjection\AddCacheWarmerPass;
1617

@@ -50,7 +51,7 @@ public function testThatCacheWarmersAreProcessedInPriorityOrder()
5051
new Reference('my_cache_warmer_service3'),
5152
));
5253

53-
$addCacheWarmerPass = new AddCacheWarmerPass();
54+
$addCacheWarmerPass = new AddCacheWarmerPass('cache_warmer', 'kernel.cache_warmer');
5455
$addCacheWarmerPass->process($container);
5556
}
5657

@@ -70,7 +71,7 @@ public function testThatCompilerPassIsIgnoredIfThereIsNoCacheWarmerDefinition()
7071
->will($this->returnValue(false));
7172
$definition->expects($this->never())->method('replaceArgument');
7273

73-
$addCacheWarmerPass = new AddCacheWarmerPass();
74+
$addCacheWarmerPass = new AddCacheWarmerPass('cache_warmer', 'kernel.cache_warmer');
7475
$addCacheWarmerPass->process($container);
7576
}
7677

@@ -93,7 +94,7 @@ public function testThatCacheWarmersMightBeNotDefined()
9394

9495
$definition->expects($this->never())->method('replaceArgument');
9596

96-
$addCacheWarmerPass = new AddCacheWarmerPass();
97+
$addCacheWarmerPass = new AddCacheWarmerPass('cache_warmer', 'kernel.cache_warmer');
9798
$addCacheWarmerPass->process($container);
9899
}
99100
}

0 commit comments

Comments
 (0)