2015-03-25 5 views
1

Je 2+ Symfony\Component\Console\Command, dont chacun renvoie un morceau de configuration Symfony\Component\Config\Definition\Builder\TreeBuilder:Comment fusionner sans pièces de configuration Ecraser jointes à l'aide de Symfony/Config ~ 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() 

    ; 
} 
} 

et ils sont combinés en une configuration en utilisant le 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; 
} 
} 

tout fonctionne lorsqu'il est ajouté à la configuration d'une seule commande. Lorsque j'essaie d'ajouter une seconde, il écrase le précédent ajouté. Comment puis-je réparer ça?

devrait être:

codio: 
    lorem: ABC 
    ipsum: 123 
    project: 
     foo: 
      ... 
     bar: 
      ... 

actuel:

codio: 
    lorem: ABC 
    ipsum: 123 
    project: 
     bar: 
      ... 

Répondre