Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement service-based Resource (cache) validation
- Loading branch information
Showing
32 changed files
with
767 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/ConfigCachePass.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler; | ||
|
||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
|
||
/** | ||
* Adds services tagged config_cache.resource_checker to the config_cache_factory service, ordering them by priority. | ||
* | ||
* @author Matthias Pigulla <mp@webfactory.de> | ||
* @author Benjamin Klotz <bk@webfactory.de> | ||
*/ | ||
class ConfigCachePass implements CompilerPassInterface | ||
{ | ||
public function process(ContainerBuilder $container) | ||
{ | ||
$resourceCheckers = array(); | ||
|
||
foreach ($container->findTaggedServiceIds('config_cache.resource_checker') as $id => $tags) { | ||
$priority = isset($tags[0]['priority']) ? $tags[0]['priority'] : 0; | ||
$resourceCheckers[$priority][] = new Reference($id); | ||
} | ||
|
||
if (empty($resourceCheckers)) { | ||
return; | ||
} | ||
|
||
// sort by priority and flatten | ||
krsort($resourceCheckers); | ||
$resourceCheckers = call_user_func_array('array_merge', $resourceCheckers); | ||
|
||
$container->getDefinition('config_cache_factory')->replaceArgument(0, $resourceCheckers); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/ConfigCachePassTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler; | ||
|
||
use Symfony\Component\DependencyInjection\Reference; | ||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ConfigCachePass; | ||
|
||
class ConfigCachePassTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testThatCheckersAreProcessedInPriorityOrder() | ||
{ | ||
$services = array( | ||
'checker_2' => array(0 => array('priority' => 100)), | ||
'checker_1' => array(0 => array('priority' => 200)), | ||
'checker_3' => array(), | ||
); | ||
|
||
$definition = $this->getMock('Symfony\Component\DependencyInjection\Definition'); | ||
$container = $this->getMock( | ||
'Symfony\Component\DependencyInjection\ContainerBuilder', | ||
array('findTaggedServiceIds', 'getDefinition', 'hasDefinition') | ||
); | ||
|
||
$container->expects($this->atLeastOnce()) | ||
->method('findTaggedServiceIds') | ||
->will($this->returnValue($services)); | ||
$container->expects($this->atLeastOnce()) | ||
->method('getDefinition') | ||
->with('config_cache_factory') | ||
->will($this->returnValue($definition)); | ||
|
||
$definition->expects($this->once()) | ||
->method('replaceArgument') | ||
->with(0, array( | ||
new Reference('checker_1'), | ||
new Reference('checker_2'), | ||
new Reference('checker_3'), | ||
)); | ||
|
||
$pass = new ConfigCachePass(); | ||
$pass->process($container); | ||
} | ||
|
||
public function testThatCheckersCanBeMissing() | ||
{ | ||
$definition = $this->getMock('Symfony\Component\DependencyInjection\Definition'); | ||
$container = $this->getMock( | ||
'Symfony\Component\DependencyInjection\ContainerBuilder', | ||
array('findTaggedServiceIds') | ||
); | ||
|
||
$container->expects($this->atLeastOnce()) | ||
->method('findTaggedServiceIds') | ||
->will($this->returnValue(array())); | ||
|
||
$pass = new ConfigCachePass(); | ||
$pass->process($container); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.