diff --git a/src/Symfony/Component/DependencyInjection/CHANGELOG.md b/src/Symfony/Component/DependencyInjection/CHANGELOG.md index 8f5d6b32c8..b159ddba20 100644 --- a/src/Symfony/Component/DependencyInjection/CHANGELOG.md +++ b/src/Symfony/Component/DependencyInjection/CHANGELOG.md @@ -1,6 +1,12 @@ CHANGELOG ========= +2.2.0 +----- + + * added PrependExtensionInterface (to be able to allow extensions to prepend + application configuration settings for any Bundle) + 2.1.0 ----- diff --git a/src/Symfony/Component/DependencyInjection/Compiler/MergeExtensionConfigurationPass.php b/src/Symfony/Component/DependencyInjection/Compiler/MergeExtensionConfigurationPass.php index a9beb5b9e2..d2c98314e2 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/MergeExtensionConfigurationPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/MergeExtensionConfigurationPass.php @@ -29,6 +29,12 @@ class MergeExtensionConfigurationPass implements CompilerPassInterface $definitions = $container->getDefinitions(); $aliases = $container->getAliases(); + foreach ($container->getExtensions() as $extension) { + if ($extension instanceof PrependExtensionInterface) { + $extension->prepend($container); + } + } + foreach ($container->getExtensions() as $name => $extension) { if (!$config = $container->getExtensionConfig($name)) { // this extension was not called diff --git a/src/Symfony/Component/DependencyInjection/Compiler/PrependExtensionInterface.php b/src/Symfony/Component/DependencyInjection/Compiler/PrependExtensionInterface.php new file mode 100644 index 0000000000..bba1b6cd46 --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Compiler/PrependExtensionInterface.php @@ -0,0 +1,24 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\DependencyInjection\Compiler; + +use Symfony\Component\DependencyInjection\ContainerBuilder; + +interface PrependExtensionInterface +{ + /** + * Allow an extension to prepend the extension configurations. + * + * @param ContainerBuilder $container + */ + public function prepend(ContainerBuilder $container); +} diff --git a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php index 30514cc55d..44200ac061 100644 --- a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php +++ b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php @@ -465,6 +465,21 @@ class ContainerBuilder extends Container implements TaggedContainerInterface return $this->extensionConfigs[$name]; } + /** + * Prepends a config array to the configs of the given extension. + * + * @param string $name The name of the extension + * @param array $config The config to set + */ + public function prependExtensionConfig($name, array $config) + { + if (!isset($this->extensionConfigs[$name])) { + $this->extensionConfigs[$name] = array(); + } + + array_unshift($this->extensionConfigs[$name], $config); + } + /** * Compiles the container. * diff --git a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php index c9e6b07847..66658efdeb 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php @@ -548,6 +548,28 @@ class ContainerBuilderTest extends \PHPUnit_Framework_TestCase $container->compile(); $container->setDefinition('a', new Definition()); } + + /** + * @covers Symfony\Component\DependencyInjection\ContainerBuilder::getExtensionConfig + * @covers Symfony\Component\DependencyInjection\ContainerBuilder::prependExtensionConfig + */ + public function testExtensionConfig() + { + $container = new ContainerBuilder(); + + $configs = $container->getExtensionConfig('foo'); + $this->assertEmpty($configs); + + $first = array('foo' => 'bar'); + $container->prependExtensionConfig('foo', $first); + $configs = $container->getExtensionConfig('foo'); + $this->assertEquals(array($first), $configs); + + $second = array('ding' => 'dong'); + $container->prependExtensionConfig('foo', $second); + $configs = $container->getExtensionConfig('foo'); + $this->assertEquals(array($second, $first), $configs); + } } class FooClass {} diff --git a/src/Symfony/Component/HttpKernel/.gitignore b/src/Symfony/Component/HttpKernel/.gitignore index 44de97a36a..38c15605ed 100644 --- a/src/Symfony/Component/HttpKernel/.gitignore +++ b/src/Symfony/Component/HttpKernel/.gitignore @@ -1,4 +1,5 @@ vendor/ composer.lock phpunit.xml - +Tests/ProjectContainer.php +Tests/classes.map \ No newline at end of file