Allowed extensions to inline compiler passes
This commit is contained in:
parent
a630d87d57
commit
6c50013b12
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Compiler;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
|
||||
/**
|
||||
* A pass to automatically process extensions if they implement
|
||||
* CompilerPassInterface.
|
||||
*
|
||||
* @author Wouter J <wouter@wouterj.nl>
|
||||
*/
|
||||
class ExtensionCompilerPass implements CompilerPassInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
foreach ($container->getExtensions() as $extension) {
|
||||
if (!$extension instanceof CompilerPassInterface) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$extension->process($container);
|
||||
}
|
||||
}
|
||||
}
|
@ -45,6 +45,7 @@ class PassConfig
|
||||
$this->mergePass = new MergeExtensionConfigurationPass();
|
||||
|
||||
$this->optimizationPasses = array(
|
||||
new ExtensionCompilerPass(),
|
||||
new ResolveDefinitionTemplatesPass(),
|
||||
new DecoratorServicePass(),
|
||||
new ResolveParameterPlaceHoldersPass(),
|
||||
|
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Compiler\ExtensionCompilerPass;
|
||||
|
||||
/**
|
||||
* @author Wouter J <wouter@wouterj.nl>
|
||||
*/
|
||||
class ExtensionCompilerPassTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $container;
|
||||
private $pass;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->container = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder');
|
||||
$this->pass = new ExtensionCompilerPass();
|
||||
}
|
||||
|
||||
public function testProcess()
|
||||
{
|
||||
$extension1 = $this->createExtensionMock(true);
|
||||
$extension1->expects($this->once())->method('process');
|
||||
$extension2 = $this->createExtensionMock(false);
|
||||
$extension3 = $this->createExtensionMock(false);
|
||||
$extension4 = $this->createExtensionMock(true);
|
||||
$extension4->expects($this->once())->method('process');
|
||||
|
||||
$this->container->expects($this->any())
|
||||
->method('getExtensions')
|
||||
->will($this->returnValue(array($extension1, $extension2, $extension3, $extension4)))
|
||||
;
|
||||
|
||||
$this->pass->process($this->container);
|
||||
}
|
||||
|
||||
private function createExtensionMock($hasInlineCompile)
|
||||
{
|
||||
return $this->getMock('Symfony\Component\DependencyInjection\\'.(
|
||||
$hasInlineCompile
|
||||
? 'Compiler\CompilerPassInterface'
|
||||
: 'Extension\ExtensionInterface'
|
||||
));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user