Skip to content

Commit 0cce93c

Browse files
committed
feature #21375 [FrameworkBundle][Config] Move ConfigCachePass from FrameworkBundle to Config (Deamon)
This PR was merged into the 3.3-dev branch. Discussion ---------- [FrameworkBundle][Config] Move ConfigCachePass from FrameworkBundle to Config | Q | A | ------------- | --- | Branch? | master<!--see comment below--> | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | yes | Tests pass? | yes/no | Fixed tickets | - <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | <!--highly recommended for new features--> This MR is part of the #21284 todo list <!-- - Bug fixes must be submitted against the lowest branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too). - Features and deprecations must be submitted against the master branch. - Please fill in this template according to the PR you're about to submit. - Replace this comment by a description of what your PR is solving. --> Commits ------- bce445f452 Move ConfigCachePass from FrameworkBundle to Config
2 parents 5de8bd1 + e77776f commit 0cce93c

File tree

4 files changed

+115
-1
lines changed

4 files changed

+115
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ CHANGELOG
77
* added `ReflectionClassResource` class
88
* added second `$exists` constructor argument to `ClassExistenceResource`
99
* made `ClassExistenceResource` work with interfaces and traits
10+
* added `ConfigCachePass` (originally in FrameworkBundle)
1011

1112
3.0.0
1213
-----
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
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 <[email protected]>
22+
* @author Benjamin Klotz <[email protected]>
23+
*/
24+
class ConfigCachePass implements CompilerPassInterface
25+
{
26+
use PriorityTaggedServiceTrait;
27+
28+
private $factoryServiceId;
29+
private $resourceCheckerTag;
30+
31+
public function __construct($factoryServiceId = 'config_cache_factory', $resourceCheckerTag = 'config_cache.resource_checker')
32+
{
33+
$this->factoryServiceId = $factoryServiceId;
34+
$this->resourceCheckerTag = $resourceCheckerTag;
35+
}
36+
37+
public function process(ContainerBuilder $container)
38+
{
39+
$resourceCheckers = $this->findAndSortTaggedServices($this->resourceCheckerTag, $container);
40+
41+
if (empty($resourceCheckers)) {
42+
return;
43+
}
44+
45+
$container->getDefinition($this->factoryServiceId)->replaceArgument(0, $resourceCheckers);
46+
}
47+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
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;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\DependencyInjection\Reference;
16+
use Symfony\Component\Config\DependencyInjection\ConfigCachePass;
17+
18+
class ConfigCachePassTest extends TestCase
19+
{
20+
public function testThatCheckersAreProcessedInPriorityOrder()
21+
{
22+
$services = array(
23+
'checker_2' => array(0 => array('priority' => 100)),
24+
'checker_1' => array(0 => array('priority' => 200)),
25+
'checker_3' => array(0 => array()),
26+
);
27+
28+
$definition = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->getMock();
29+
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('findTaggedServiceIds', 'getDefinition', 'hasDefinition'))->getMock();
30+
31+
$container->expects($this->atLeastOnce())
32+
->method('findTaggedServiceIds')
33+
->will($this->returnValue($services));
34+
$container->expects($this->atLeastOnce())
35+
->method('getDefinition')
36+
->with('config_cache_factory')
37+
->will($this->returnValue($definition));
38+
39+
$definition->expects($this->once())
40+
->method('replaceArgument')
41+
->with(0, array(
42+
new Reference('checker_1'),
43+
new Reference('checker_2'),
44+
new Reference('checker_3'),
45+
));
46+
47+
$pass = new ConfigCachePass();
48+
$pass->process($container);
49+
}
50+
51+
public function testThatCheckersCanBeMissing()
52+
{
53+
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('findTaggedServiceIds'))->getMock();
54+
55+
$container->expects($this->atLeastOnce())
56+
->method('findTaggedServiceIds')
57+
->will($this->returnValue(array()));
58+
59+
$pass = new ConfigCachePass();
60+
$pass->process($container);
61+
}
62+
}

composer.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@
2020
"symfony/filesystem": "~2.8|~3.0"
2121
},
2222
"require-dev": {
23-
"symfony/yaml": "~3.0"
23+
"symfony/yaml": "~3.0",
24+
"symfony/dependency-injection": "~3.2"
25+
},
26+
"conflict": {
27+
"symfony/dependency-injection": "<3.2"
2428
},
2529
"suggest": {
2630
"symfony/yaml": "To use the yaml reference dumper"

0 commit comments

Comments
 (0)