I'm sorry to say I can't find a way to add a default value to a "symfony/config": "2.6.4" ConfigurationInterface !
What's wanted is this type of config :
X:
Y:
- test
- testing
With default to :
X:
Y:
- test
By "default" I mean : if Y config branch is not set on the read configuration file, the $processor->processConfiguration should add it (and it does ! If I remove the ->prototype...)
Here is my code :
class Definition implements ConfigurationInterface
{
/**
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root("X");
$rootNode
->children()
->arrayNode("Y")
->addDefaultsIfNotSet()
->info("Multiple values can be used")
->cannotBeEmpty()
->addDefaultIfNotSet()
->defaultValue(array("test"))
->prototype("scalar")
->validate()
->ifNotInArray(array("test", "testing"))
->thenInvalid("Invalid value %s")
->end()
->end()
->end()
->end()
;
return $treeBuilder;
}
}
Sure, I read this question Using the Symfony2 configuration class, how do I define an array node whose children don't have keys?
My current code implements this way as you can read, but it does not work, my code throws :
[Symfony\Component\Config\Definition\Exception\InvalidDefinitionException]
->addDefaultsIfNotSet() is not applicable to prototype nodes at path "X.Y"