1
我有2+ Symfony\Component\Console\Command
,其中的每一个返回一个片配置Symfony\Component\Config\Definition\Builder\TreeBuilder
的:如何在不使用覆盖所附配置份合并的Symfony /配置〜2.6
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:
...
是的。它没有取得任何结果。 – Gander 2015-03-25 17:32:48