【发布时间】:2015-03-13 07:44:52
【问题描述】:
很抱歉,我找不到将默认值添加到“symfony/config”的方法:“2.6.4”ConfigurationInterface!
我们想要的是这种类型的配置:
X:
Y:
- test
- testing
默认为:
X:
Y:
- test
“默认”是指:如果未在读取的配置文件上设置 Y config 分支,则 $processor->processConfiguration 应该添加它(它会添加它!如果我删除 ->prototype...)
这是我的代码:
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"
【问题讨论】: