我的配置节点source
能够支持string
和array
两种类型的值吗?
从string
中获取:
# Valid configuration 1
my_bundle:
source: %kernel.root_dir%/../Resources/config/source.json
从 数组
获取数据:
# Valid configuration 2
my_bundle:
source:
operations: []
commands: []
扩展类将能够区分它们:
扩展类将能够区分它们:
if (is_array($config['source']) {
// Bootstrap from array
} else {
// Bootstrap from file
}
我可能会使用类似这样的东西:
$rootNode->children()
->variableNode('source')
->validate()
->ifTrue(function ($v) { return !is_string($v) && !is_array($v); })
->thenInvalid('Configuration value must be either string or array.')
->end()
->end()
->end();
但是我如何对变量节点上的source
结构(操作、命令等)添加约束条件(只有在其值为array
类型时才应强制执行)?
path
、operations
和commands
被设置时,我应该处理这种情况。+1给我。 - gremo