[Config] implements feedback

This commit is contained in:
Victor Berchet 2012-02-20 19:15:01 +01:00
parent bc122bdb2d
commit 4feba09aa9
4 changed files with 13 additions and 6 deletions

View File

@ -217,7 +217,7 @@ class Configuration implements ConfigurationInterface
->fixXmlConfig('resource') ->fixXmlConfig('resource')
->children() ->children()
->arrayNode('resources') ->arrayNode('resources')
->addDefaultChildrenWhenNoneSet() ->addDefaultChildrenIfNoneSet()
->prototype('scalar')->defaultValue('FrameworkBundle:Form')->end() ->prototype('scalar')->defaultValue('FrameworkBundle:Form')->end()
->validate() ->validate()
->ifTrue(function($v) {return !in_array('FrameworkBundle:Form', $v); }) ->ifTrue(function($v) {return !in_array('FrameworkBundle:Form', $v); })

View File

@ -54,7 +54,7 @@ class Configuration implements ConfigurationInterface
->fixXmlConfig('resource') ->fixXmlConfig('resource')
->children() ->children()
->arrayNode('resources') ->arrayNode('resources')
->addDefaultChildrenWhenNoneSet() ->addDefaultChildrenIfNoneSet()
->prototype('scalar')->defaultValue('form_div_layout.html.twig')->end() ->prototype('scalar')->defaultValue('form_div_layout.html.twig')->end()
->setExample(array('MyBundle::form.html.twig')) ->setExample(array('MyBundle::form.html.twig'))
->validate() ->validate()

View File

@ -109,7 +109,7 @@ class ArrayNodeDefinition extends NodeDefinition implements ParentNodeDefinition
* *
* @return ArrayNodeDefinition * @return ArrayNodeDefinition
*/ */
public function addDefaultChildrenWhenNoneSet($children = null) public function addDefaultChildrenIfNoneSet($children = null)
{ {
$this->addDefaultChildren = null === $children ? 'defaults' : $children; $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) 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)
);
}
} }
/** /**

View File

@ -49,6 +49,7 @@ class ArrayNodeDefinitionTest extends \PHPUnit_Framework_TestCase
{ {
return array( return array(
array('defaultValue', array(array())), array('defaultValue', array(array())),
array('addDefaultChildrenIfNoneSet', array()),
array('requiresAtLeastOneElement', array()), array('requiresAtLeastOneElement', array()),
array('useAttributeAsKey', array('foo')) array('useAttributeAsKey', array('foo'))
); );
@ -72,7 +73,7 @@ class ArrayNodeDefinitionTest extends \PHPUnit_Framework_TestCase
$node = new ArrayNodeDefinition('root'); $node = new ArrayNodeDefinition('root');
$node $node
->defaultValue(array()) ->defaultValue(array())
->addDefaultChildrenWhenNoneSet('foo') ->addDefaultChildrenIfNoneSet('foo')
->prototype('array') ->prototype('array')
; ;
$node->getNode(); $node->getNode();
@ -82,7 +83,7 @@ class ArrayNodeDefinitionTest extends \PHPUnit_Framework_TestCase
{ {
$node = new ArrayNodeDefinition('root'); $node = new ArrayNodeDefinition('root');
$node $node
->addDefaultChildrenWhenNoneSet() ->addDefaultChildrenIfNoneSet()
->prototype('array') ->prototype('array')
; ;
$tree = $node->getNode(); $tree = $node->getNode();
@ -93,7 +94,7 @@ class ArrayNodeDefinitionTest extends \PHPUnit_Framework_TestCase
{ {
$node = new ArrayNodeDefinition('root'); $node = new ArrayNodeDefinition('root');
$node $node
->addDefaultChildrenWhenNoneSet() ->addDefaultChildrenIfNoneSet()
->prototype('array') ->prototype('array')
->prototype('array') ->prototype('array')
; ;