make it possible for bundles extensions to prepend settings into the application configuration of any Bundle
This commit is contained in:
parent
425f6f57df
commit
d7a1154154
@ -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
|
||||
-----
|
||||
|
||||
|
@ -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
|
||||
|
@ -0,0 +1,24 @@
|
||||
<?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\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);
|
||||
}
|
@ -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.
|
||||
*
|
||||
|
@ -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 {}
|
||||
|
3
src/Symfony/Component/HttpKernel/.gitignore
vendored
3
src/Symfony/Component/HttpKernel/.gitignore
vendored
@ -1,4 +1,5 @@
|
||||
vendor/
|
||||
composer.lock
|
||||
phpunit.xml
|
||||
|
||||
Tests/ProjectContainer.php
|
||||
Tests/classes.map
|
Reference in New Issue
Block a user