etiennenoel
etiennenoel

Reputation: 575

Symfony2 specify undeclared config for a bundle

I want to inject configuration in my bundle. My configuration looks like this:

osc_storage:
    storages:
        image:
            adapter: aws_s3
            options:
                option1: 'test'
                option2: 'test'
                ...

Basically, what I want, is to not define what the options field will contain and simply inject this. In my configTreeBuilder, I have the following:

public function getConfigTreeBuilder()
{
    $treeBuilder = new TreeBuilder();
    $rootNode = $treeBuilder->root('osc_storage');


    // Here you should define the parameters that are allowed to
    // configure your bundle. See the documentation linked above for
    // more information on that topic.

    $rootNode
        ->children()
            ->arrayNode('storages')
                ->prototype('array')
                    ->children()
                        ->scalarNode('adapter')->end()
                        ->arrayNode('options')
                            ->prototype('array')
                            ->end()
                        ->end()
                    ->end()
                ->end()
            ->end()
        ->end();

    return $treeBuilder;
}

However, I get the following error:

Invalid type for path "osc_storage.storages.image.options.option1". Expected array, but got string

Is there a way to specify that you know that this is an associative array but don't want to specify each node ?

Upvotes: 1

Views: 36

Answers (1)

Etienne Noël
Etienne Noël

Reputation: 6166

You could do something like that:

 ->arrayNode('storages')
     ->prototype('array')
         ->children()
             ->scalarNode('adapter')->end()
             ->variableNode('options')->end()
         ->end()
     ->end()
 ->end()

Upvotes: 1

Related Questions