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

[DependencyInjection] allow null values for root nodes in YAML configs #25891

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,16 @@ public function addClassResource(\ReflectionClass $class)
* @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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ private function loadFromExtensions(array $content)
continue;
}

if (!is_array($values)) {
if (!is_array($values) && null !== $values) {
$values = array();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
project: ~
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,17 @@ public function testExtensions()
}
}

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());
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.