bug #25891 [DependencyInjection] allow null values for root nodes in YAML configs (xabbuh)
This PR was merged into the 2.7 branch.
Discussion
----------
[DependencyInjection] allow null values for root nodes in YAML configs
| Q | A
| ------------- | ---
| Branch? | 2.7
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #25760
| License | MIT
| Doc PR |
Commits
-------
52dd825bf1
allow null values for root nodes in YAML configs
This commit is contained in:
commit
73cbb01953
@ -271,12 +271,16 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
||||
* @throws BadMethodCallException When this ContainerBuilder is frozen
|
||||
* @throws \LogicException if the container is frozen
|
||||
*/
|
||||
public function loadFromExtension($extension, array $values = array())
|
||||
public function loadFromExtension($extension, array $values = null)
|
||||
{
|
||||
if ($this->isFrozen()) {
|
||||
throw new BadMethodCallException('Cannot load from an extension on a frozen container.');
|
||||
}
|
||||
|
||||
if (func_num_args() < 2) {
|
||||
$values = array();
|
||||
}
|
||||
|
||||
$namespace = $this->getExtension($extension)->getAlias();
|
||||
|
||||
$this->extensionConfigs[$namespace][] = $values;
|
||||
|
@ -425,7 +425,7 @@ class YamlFileLoader extends FileLoader
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!is_array($values)) {
|
||||
if (!is_array($values) && null !== $values) {
|
||||
$values = array();
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,14 @@ class ProjectExtension implements ExtensionInterface
|
||||
{
|
||||
public function load(array $configs, ContainerBuilder $configuration)
|
||||
{
|
||||
$config = call_user_func_array('array_merge', $configs);
|
||||
$configuration->setParameter('project.configs', $configs);
|
||||
$configs = array_filter($configs);
|
||||
|
||||
if ($configs) {
|
||||
$config = call_user_func_array('array_merge', $configs);
|
||||
} else {
|
||||
$config = array();
|
||||
}
|
||||
|
||||
$configuration->setDefinition('project.service.bar', new Definition('FooClass'));
|
||||
$configuration->setParameter('project.parameter.bar', isset($config['foo']) ? $config['foo'] : 'foobar');
|
||||
|
@ -0,0 +1 @@
|
||||
project: ~
|
@ -207,6 +207,17 @@ class YamlFileLoaderTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function testExtensionWithNullConfig()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->registerExtension(new \ProjectExtension());
|
||||
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
|
||||
$loader->load('null_config.yml');
|
||||
$container->compile();
|
||||
|
||||
$this->assertSame(array(null), $container->getParameter('project.configs'));
|
||||
}
|
||||
|
||||
public function testSupports()
|
||||
{
|
||||
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator());
|
||||
|
Reference in New Issue
Block a user