我有2 + Symfony\Component\Console\Command
,每个都返回一段配置Symfony\Component\Config\Definition\Builder\TreeBuilder
:
class ProjectFooCommand extends Command {
public function getConfigTree()
{
return (new TreeBuilder())
->root('project')
->children()
->arrayNode('foo')
->children()
// specific
->end()
->end()
->end()
;
}
}
class ProjectBarCommand extends Command {
public function getConfigTree()
{
return (new TreeBuilder())
->root('project')
->children()
->arrayNode('bar')
->children()
// specific
->end()
->end()
->end()
;
}
}
使用ArrayNodeDefinition::append()
:
class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder()
{
$builder = new TreeBuilder();
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('codio');
$rootNode
->children()
->scalarNode('lorem')->defaultValue('ABC')->end()
->scalarNode('ipsum')->defaultValue('123')->end()
->end()
;
foreach ($this->application->all() as $command)
{
$rootNode->append($command->getConfigTree());
}
return $treeBuilder;
}
}
当它被添加到只有一个命令的配置时,一切正常。当我尝试添加第二个时,它会覆盖之前添加的。我该如何解决这个问题?
应该是:
codio:
lorem: ABC
ipsum: 123
project:
foo:
...
bar:
...
电流:
codio:
lorem: ABC
ipsum: 123
project:
bar:
...
答案 0 :(得分:0)
您是否尝试过cannotBeOverwritten(true)
方法:http://api.symfony.com/2.7/Symfony/Component/Config/Definition/Builder/NodeDefinition.html#method_cannotBeOverwritten?