我的配置節點source
可以同時支持string
和array
值嗎?讓配置節點在Symfony 2配置中支持字符串和數組?
採購從string
:
# Valid configuration 1
my_bundle:
source: %kernel.root_dir%/../Resources/config/source.json
採購從array
:
# 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();
但如何CA我加上source
的結構約束(操作,命令等)的變量節點(應該當其值array
型只執行)?
還不錯。當'path'和'operations'和'commands'設置時,我應該處理這種情況。 +1給我 – gremo 2013-04-15 11:27:18