8000 [HttpKernel] Add arguments for cache passes · symfony/symfony@edcd138 · GitHub
[go: up one dir, main page]

Skip to content

Commit edcd138

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

File tree

5 files changed

+71
-8
lines changed

5 files changed

+71
-8
lines changed

src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php

Lines changed: 2 additions & 2 deletions
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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,33 @@
2222
*/
2323
class AddCacheClearerPass implements CompilerPassInterface
2424
{
25+
private $tag;
26+
private $serviceName;
27+
28+
public function __construct($serviceName = 'cache_clearer', $tag = 'kernel.cache_clearer')
29+
{
30+
if (null === $serviceName || null === $tag) {
31+
@trigger_error('The '.static::class.' class\' constructor needs two parameters since version 3.2, and will become required in 4.0.', E_USER_DEPRECATED);
32+
}
33+
34+
$this->serviceName = $serviceName;
35+
$this->tag = $tag;
36+
}
37+
2538
/**
2639
* {@inheritdoc}
2740
*/
2841
public function process(ContainerBuilder $container)
2942
{
30-
if (!$container->hasDefinition('cache_clearer')) {
43+
if (!$container->hasDefinition($this->serviceName)) {
3144
return;
3245
}
3346

3447
$clearers = array();
35-
foreach ($container->findTaggedServiceIds('kernel.cache_clearer') as $id => $attributes) {
48+
foreach ($container->findTaggedServiceIds($this->tag) as $id => $attributes) {
3649
$clearers[] = new Reference($id);
3750
}
3851

39-
$container->getDefinition('cache_clearer')->replaceArgument(0, $clearers);
52+
$container->getDefinition($this->serviceName)->replaceArgument(0, $clearers);
4053
}
4154
}

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,34 @@ class AddCacheWarmerPass implements CompilerPassInterface
2424
{
2525
use PriorityTaggedServiceTrait;
2626

27+
private $tag;
28+
private $serviceName;
29+
30+
public function __construct($serviceName = 'cache_warmer', $tag = 'kernel.cache_warmer')
31+
{
32+
if (2 > func_num_args()) {
33+
@trigger_error('The '.static::class.' class\' constructor needs two parameters since version 3.2, and will become required in 4.0.', E_USER_DEPRECATED);
34+
}
35+
36+
$this->serviceName = $serviceName;
37+
$this->tag = $tag;
38+
}
39+
2740
/**
2841
* {@inheritdoc}
2942
*/
3043
public function process(ContainerBuilder $container)
3144
{
32-
if (!$container->hasDefinition('cache_warmer')) {
45+
if (!$container->hasDefinition($this->serviceName)) {
3346
return;
3447
}
3548

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

3851
if (empty($warmers)) {
3952
return;
4053
}
4154

42-
$container->getDefinition('cache_warmer')->replaceArgument(0, $warmers);
55+
$container->getDefinition($this->serviceName)->replaceArgument(0, $warmers);
4356
}
4457
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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\Tests\DependencyInjection;
13+
14+
use Symfony\Bridge\PhpUnit\ErrorAssert;
15+
use Symfony\Component\HttpKernel\DependencyInjection\AddCacheClearerPass;
16+
17+
class AddCacheClearerPassTest extends \PHPUnit_Framework_TestCase
18+
{
19+
/**
20+
* @group legacy
21+
* @requires function Symfony\Bridge\PhpUnit\ErrorAssert::assertDeprecationsAreTriggered
22+
*/
23+
public function testThatADeprecatedErrorIsTriggeredWhenGivingNoConstructorArgs()
24+
{
25+
ErrorAssert::assertDeprecationsAreTriggered('The '.AddCacheClearerPass::class.' class\' constructor needs two parameters since version 3.2, and will become required in 4.0.', function () { new AddCacheClearerPass(); });
26+
}
27+
}

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

Lines changed: 10 additions & 0 deletions
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

@@ -96,4 +97,13 @@ public function testThatCacheWarmersMightBeNotDefined()
9697
$addCacheWarmerPass = new AddCacheWarmerPass();
9798
$addCacheWarmerPass->process($container);
9899
}
100+
101+
/**
102+
* @group legacy
103+
* @requires function Symfony\Bridge\PhpUnit\ErrorAssert::assertDeprecationsAreTriggered
104+
*/
105+
public function testThatADeprecatedErrorIsTriggeredWhenGivingNoConstructorArgs()
106+
{
107+
ErrorAssert::assertDeprecationsAreTriggered('The '.AddCacheWarmerPass::class.' class\' constructor needs two parameters since version 3.2, and will become required in 4.0.', function () { new AddCacheWarmerPass(); });
108+
}
99109
}

0 commit comments

Comments
 (0)
0