diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index 855bf6f81f..38eac5879a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -217,7 +217,7 @@ class Configuration implements ConfigurationInterface ->fixXmlConfig('resource') ->children() ->arrayNode('resources') - ->addDefaultChildrenWhenNoneSet() + ->addDefaultChildrenIfNoneSet() ->prototype('scalar')->defaultValue('FrameworkBundle:Form')->end() ->validate() ->ifTrue(function($v) {return !in_array('FrameworkBundle:Form', $v); }) diff --git a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php index 9829fad629..9802094b70 100644 --- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php @@ -54,7 +54,7 @@ class Configuration implements ConfigurationInterface ->fixXmlConfig('resource') ->children() ->arrayNode('resources') - ->addDefaultChildrenWhenNoneSet() + ->addDefaultChildrenIfNoneSet() ->prototype('scalar')->defaultValue('form_div_layout.html.twig')->end() ->setExample(array('MyBundle::form.html.twig')) ->validate() diff --git a/src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php b/src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php index 4ac4b18895..4717e5e2dd 100644 --- a/src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +++ b/src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php @@ -109,7 +109,7 @@ class ArrayNodeDefinition extends NodeDefinition implements ParentNodeDefinition * * @return ArrayNodeDefinition */ - public function addDefaultChildrenWhenNoneSet($children = null) + public function addDefaultChildrenIfNoneSet($children = null) { $this->addDefaultChildren = null === $children ? 'defaults' : $children; @@ -369,6 +369,12 @@ class ArrayNodeDefinition extends NodeDefinition implements ParentNodeDefinition sprintf('->defaultValue() is not applicable to concrete nodes at path "%s"', $path) ); } + + if (false !== $this->addDefaultChildren) { + throw new InvalidDefinitionException( + sprintf('->addDefaultChildrenIfNoneSet() is not applicable to concrete nodes at path "%s"', $path) + ); + } } /** diff --git a/tests/Symfony/Tests/Component/Config/Definition/Builder/ArrayNodeDefinitionTest.php b/tests/Symfony/Tests/Component/Config/Definition/Builder/ArrayNodeDefinitionTest.php index 35d62a8b3e..93903c6302 100644 --- a/tests/Symfony/Tests/Component/Config/Definition/Builder/ArrayNodeDefinitionTest.php +++ b/tests/Symfony/Tests/Component/Config/Definition/Builder/ArrayNodeDefinitionTest.php @@ -49,6 +49,7 @@ class ArrayNodeDefinitionTest extends \PHPUnit_Framework_TestCase { return array( array('defaultValue', array(array())), + array('addDefaultChildrenIfNoneSet', array()), array('requiresAtLeastOneElement', array()), array('useAttributeAsKey', array('foo')) ); @@ -72,7 +73,7 @@ class ArrayNodeDefinitionTest extends \PHPUnit_Framework_TestCase $node = new ArrayNodeDefinition('root'); $node ->defaultValue(array()) - ->addDefaultChildrenWhenNoneSet('foo') + ->addDefaultChildrenIfNoneSet('foo') ->prototype('array') ; $node->getNode(); @@ -82,7 +83,7 @@ class ArrayNodeDefinitionTest extends \PHPUnit_Framework_TestCase { $node = new ArrayNodeDefinition('root'); $node - ->addDefaultChildrenWhenNoneSet() + ->addDefaultChildrenIfNoneSet() ->prototype('array') ; $tree = $node->getNode(); @@ -93,7 +94,7 @@ class ArrayNodeDefinitionTest extends \PHPUnit_Framework_TestCase { $node = new ArrayNodeDefinition('root'); $node - ->addDefaultChildrenWhenNoneSet() + ->addDefaultChildrenIfNoneSet() ->prototype('array') ->prototype('array') ;