我很抱歉地說我找不到一種方法來將一個默認值添加到「symfony/config」:「2.6.4」ConfigurationInterface!symfony/config arrayNode原型addDefaultsIfNotSet
什麼希望是這種類型的配置中:
X:
Y:
- test
- testing
隨着默認爲:
X:
Y:
- test
通過 「默認」 我的意思是:如果Y config分支未設置讀取配置文件, $ process-> processConfiguration應該添加它(如果我刪除 - >原型...)
這是我的代碼:
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;
}
}
我當前的代碼實現這種方式,你可以讀,但它不工作,我的代碼拋出:
[Symfony\Component\Config\Definition\Exception\InvalidDefinitionException]
->addDefaultsIfNotSet() is not applicable to prototype nodes at path "X.Y"