Carlos Goce
Carlos Goce

Reputation: 1665

Removing parent node on Symfony TreeBuilder

i have this yml configuration file:

services:
  myservice1: ~
  myservice2: ~

My TreeBuilder is:

$rootNode
    ->children()
        ->arrayNode('services')
            ->useAttributeAsKey('serviceName')
            ->prototype('array')
                ->children()
                ->end()
            ->end()
        ->end()
    ->end()
;

But I wish to use the following yml if that is possible:

  - myservice1: ~
  - myservice2: ~

Upvotes: 0

Views: 105

Answers (2)

Carlos Goce
Carlos Goce

Reputation: 1665

Finally i was able to do it with the following Tree Builder

$rootNode = $this->treebuilder->root('DefaultConfigurationRules');
    $rootNode
        ->isRequired()
        ->cannotBeEmpty()
        ->prototype('array')
            ->children()
                //

Upvotes: 1

Milos Tomic
Milos Tomic

Reputation: 361

That's impossible, has no point in Symfony2, and is a terrible anti-pattern. The "services" root node is handled by the DPI component and below it the DPI component expects service definitions. All root configuration nodes are specially handled by the registered configuration handlers, like services, parameters, security, framework... In a way it's like a programming language statement. You would get into a collision with other configuration parameters w/out such namespacing. You should wrap all your configuration parameters under properly namespaced names that correspond to your bundle name.

Upvotes: 0

Related Questions