Skip to content

Commit 64a0100

Browse files
committed
Move ConfigCachePass from FrameworkBundle to Config
1 parent 71b8a66 commit 64a0100

File tree

9 files changed

+127
-18
lines changed

9 files changed

+127
-18
lines changed

UPGRADE-3.3.md

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ FrameworkBundle
3434
---------------
3535

3636
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConsoleCommandPass` has been deprecated. Use `Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass` instead.
37+
38+
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ConfigCachePass` has been deprecated. Use `Symfony\Component\Config\DependencyInjection\ConfigCachePass` instead.
3739

3840
HttpKernel
3941
-----------

UPGRADE-4.0.md

+2
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ FrameworkBundle
155155
have been removed. APCu should now be automatically used when available.
156156

157157
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConsoleCommandPass` has been removed. Use `Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass` instead.
158+
159+
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ConfigCachePass` has been removed. Use `Symfony\Component\Config\DependencyInjection\ConfigCachePass` instead.
158160

159161
SecurityBundle
160162
--------------

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ CHANGELOG
1212
is disabled.
1313
* Added `GlobalVariables::getToken()`
1414
* Deprecated `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConsoleCommandPass`. Use `Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass` instead.
15+
* Deprecated `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ConfigCachePass`. Use `Symfony\Component\Console\DependencyInjection\ConfigCachePass` instead.
1516

1617
3.2.0
1718
-----

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

+6-16
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,18 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
1313

14-
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15-
use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait;
16-
use Symfony\Component\DependencyInjection\ContainerBuilder;
14+
use Symfony\Component\Config\DependencyInjection\ConfigCachePass as BaseConfigCachePass;
15+
16+
@trigger_error(sprintf('The %s class is deprecated since version 3.3 and will be removed in 4.0. Use Symfony\Component\Config\DependencyInjection\ConfigCachePass instead.', ConfigCachePass::class), E_USER_DEPRECATED);
1717

1818
/**
1919
* Adds services tagged config_cache.resource_checker to the config_cache_factory service, ordering them by priority.
2020
*
21+
* @deprecated since version 3.3, to be removed in 4.0. Use {@link BaseConfigCachePass} instead.
22+
*
2123
* @author Matthias Pigulla <mp@webfactory.de>
2224
* @author Benjamin Klotz <bk@webfactory.de>
2325
*/
24-
class ConfigCachePass implements CompilerPassInterface
26+
class ConfigCachePass extends BaseConfigCachePass
2527
{
26-
use PriorityTaggedServiceTrait;
27-
28-
public function process(ContainerBuilder $container)
29-
{
30-
$resourceCheckers = $this->findAndSortTaggedServices('config_cache.resource_checker', $container);
31-
32-
if (empty($resourceCheckers)) {
33-
return;
34-
}
35-
36-
$container->getDefinition('config_cache_factory')->replaceArgument(0, $resourceCheckers);
37-
}
3828
}

src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php

+9-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TranslationDumperPass;
3535
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\SerializerPass;
3636
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\UnusedTagsPass;
37-
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ConfigCachePass;
3837
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ValidateWorkflowsPass;
38+
use Symfony\Component\Config\DependencyInjection\Compiler\ConfigCachePass;
3939
use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass;
4040
use Symfony\Component\Debug\ErrorHandler;
4141
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -105,8 +105,15 @@ public function build(ContainerBuilder $container)
105105
$container->addCompilerPass(new UnusedTagsPass(), PassConfig::TYPE_AFTER_REMOVING);
106106
$container->addCompilerPass(new ContainerBuilderDebugDumpPass(), PassConfig::TYPE_AFTER_REMOVING);
107107
$container->addCompilerPass(new CompilerDebugDumpPass(), PassConfig::TYPE_AFTER_REMOVING);
108-
$container->addCompilerPass(new ConfigCachePass());
108+
$this->addCompilerPassIfExists($container, ConfigCachePass::class);
109109
$container->addCompilerPass(new CacheCollectorPass());
110110
}
111111
}
112+
113+
private function addCompilerPassIfExists(ContainerBuilder $container, $class, $type = PassConfig::TYPE_BEFORE_OPTIMIZATION, $priority = 0)
114+
{
115+
if (class_exists($class)) {
116+
$container->addCompilerPass(new $class(), $type, $priority);
117+
}
118+
}
112119
}

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/ConfigCachePassTest.php

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
use Symfony\Component\DependencyInjection\Reference;
1515
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ConfigCachePass;
1616

17+
/**
18+
* @group legacy
19+
*/
1720
class ConfigCachePassTest extends \PHPUnit_Framework_TestCase
1821
{
1922
public function testThatCheckersAreProcessedInPriorityOrder()

src/Symfony/Component/Config/CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
3.3.0
5+
-----
6+
7+
* added `ConfigCachePass` (originally in FrameworkBundle)
8+
49
3.0.0
510
-----
611

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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\Config\DependencyInjection;
13+
14+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15+
use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait;
16+
use Symfony\Component\DependencyInjection\ContainerBuilder;
17+
18+
/**
19+
* Adds services tagged config_cache.resource_checker to the config_cache_factory service, ordering them by priority.
20+
*
21+
* @author Matthias Pigulla <mp@webfactory.de>
22+
* @author Benjamin Klotz <bk@webfactory.de>
23+
*/
24+
class ConfigCachePass implements CompilerPassInterface
25+
{
26+
use PriorityTaggedServiceTrait;
27+
28+
public function process(ContainerBuilder $container)
29+
{
30+
$resourceCheckers = $this->findAndSortTaggedServices('config_cache.resource_checker', $container);
31+
32+
if (empty($resourceCheckers)) {
33+
return;
34+
}
35+
36+
$container->getDefinition('config_cache_factory')->replaceArgument(0, $resourceCheckers);
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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\Config\Tests\DependencyInjection\Compiler;
13+
14+
use Symfony\Component\DependencyInjection\Reference;
15+
use Symfony\Component\Config\DependencyInjection\ConfigCachePass;
16+
17+
class ConfigCachePassTest extends \PHPUnit_Framework_TestCase
18+
{
19+
public function testThatCheckersAreProcessedInPriorityOrder()
20+
{
21+
$services = array(
22+
'checker_2' => array(0 => array('priority' => 100)),
23+
'checker_1' => array(0 => array('priority' => 200)),
24+
'checker_3' => array(0 => array()),
25+
);
26+
27+
$definition = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->getMock();
28+
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('findTaggedServiceIds', 'getDefinition', 'hasDefinition'))->getMock();
29+
30+
$container->expects($this->atLeastOnce())
31+
->method('findTaggedServiceIds')
32+
->will($this->returnValue($services));
33+
$container->expects($this->atLeastOnce())
34+
->method('getDefinition')
35+
->with('config_cache_factory')
36+
->will($this->returnValue($definition));
37+
38+
$definition->expects($this->once())
39+
->method('replaceArgument')
40+
->with(0, array(
41+
new Reference('checker_1'),
42+
new Reference('checker_2'),
43+
new Reference('checker_3'),
44+
));
45+
46+
$pass = new ConfigCachePass();
47+
$pass->process($container);
48+
}
49+
50+
public function testThatCheckersCanBeMissing()
51+
{
52+
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('findTaggedServiceIds'))->getMock();
53+
54+
$container->expects($this->atLeastOnce())
55+
->method('findTaggedServiceIds')
56+
->will($this->returnValue(array()));
57+
58+
$pass = new ConfigCachePass();
59+
$pass->process($container);
60+
}
61+
}

0 commit comments

Comments
 (0)