Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 52dd825

Browse filesBrowse files
committed
allow null values for root nodes in YAML configs
1 parent 34b6bdc commit 52dd825
Copy full SHA for 52dd825

File tree

5 files changed

+26
-3
lines changed
Filter options

5 files changed

+26
-3
lines changed

‎src/Symfony/Component/DependencyInjection/ContainerBuilder.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/ContainerBuilder.php
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,12 +271,16 @@ public function addClassResource(\ReflectionClass $class)
271271
* @throws BadMethodCallException When this ContainerBuilder is frozen
272272
* @throws \LogicException if the container is frozen
273273
*/
274-
public function loadFromExtension($extension, array $values = array())
274+
public function loadFromExtension($extension, array $values = null)
275275
{
276276
if ($this->isFrozen()) {
277277
throw new BadMethodCallException('Cannot load from an extension on a frozen container.');
278278
}
279279

280+
if (func_num_args() < 2) {
281+
$values = array();
282+
}
283+
280284
$namespace = $this->getExtension($extension)->getAlias();
281285

282286
$this->extensionConfigs[$namespace][] = $values;

‎src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ private function loadFromExtensions(array $content)
425425
continue;
426426
}
427427

428-
if (!is_array($values)) {
428+
if (!is_array($values) && null !== $values) {
429429
$values = array();
430430
}
431431

‎src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/ProjectExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/ProjectExtension.php
+8-1Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@ class ProjectExtension implements ExtensionInterface
88
{
99
public function load(array $configs, ContainerBuilder $configuration)
1010
{
11-
$config = call_user_func_array('array_merge', $configs);
11+
$configuration->setParameter('project.configs', $configs);
12+
$configs = array_filter($configs);
13+
14+
if ($configs) {
15+
$config = call_user_func_array('array_merge', $configs);
16+
} else {
17+
$config = array();
18+
}
1219

1320
$configuration->setDefinition('project.service.bar', new Definition('FooClass'));
1421
$configuration->setParameter('project.parameter.bar', isset($config['foo']) ? $config['foo'] : 'foobar');
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
project: ~

‎src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,17 @@ public function testExtensions()
207207
}
208208
}
209209

210+
public function testExtensionWithNullConfig()
211+
{
212+
$container = new ContainerBuilder();
213+
$container->registerExtension(new \ProjectExtension());
214+
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
215+
$loader->load('null_config.yml');
216+
$container->compile();
217+
218+
$this->assertSame(array(null), $container->getParameter('project.configs'));
219+
}
220+
210221
public function testSupports()
211222
{
212223
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator());

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.