diff --git a/src/Symfony/Component/DependencyInjection/Compiler/ExtensionCompilerPass.php b/src/Symfony/Component/DependencyInjection/Compiler/ExtensionCompilerPass.php new file mode 100644 index 0000000000000..a9b418d497bed --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Compiler/ExtensionCompilerPass.php @@ -0,0 +1,28 @@ + + */ +class ExtensionCompilerPass implements CompilerPassInterface +{ + /** + * {@inheritdoc} + */ + public function process(ContainerBuilder $container) + { + foreach ($container->getExtensions() as $extension) { + if (!$extension instanceof CompilerPassInterface) { + continue; + } + + $extension->process($container); + } + } +} diff --git a/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php b/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php index 044529eb6d7c0..d6dee26fda766 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php @@ -45,6 +45,7 @@ public function __construct() $this->mergePass = new MergeExtensionConfigurationPass(); $this->optimizationPasses = array( + new ExtensionCompilerPass(), new ResolveDefinitionTemplatesPass(), new DecoratorServicePass(), new ResolveParameterPlaceHoldersPass(), diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ExtensionCompilerPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ExtensionCompilerPassTest.php new file mode 100644 index 0000000000000..ef690da16329e --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ExtensionCompilerPassTest.php @@ -0,0 +1,46 @@ + + */ +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' + )); + } +}