开发者

SF2 : Allow user to configure bundle without checking some part of the bundle configuration

开发者 https://www.devze.com 2023-03-17 01:47 出处:网络
I\'m actually developping a symfony 2 bundle. I would like to allow user to configure my bundle with the DIC without checking some part of the bundle configuration.

I'm actually developping a symfony 2 bundle. I would like to allow user to configure my bundle with the DIC without checking some part of the bundle configuration.

For example, the user sets this configuration :

root_node:
    node:
        key1: value1
        key2: value2
        key3: value3

And my configuration bundle is set like that :

$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('root_node');

$rootNode
    ->children()
        ->arrayNode('node')->children()->end()
    ->end();

I would like the children nodes of "node" can be configure by the user without been checking by the bundle configuration. I don't know how modify the configuration for this issue开发者_运维百科.


After some reseach on the symfony2 github repository, I found the solution. For the others who want to do the same thing, the solution is :

$rootNode
    ->children()
        ->arrayNode('node')
            ->useAttributeAsKey('node')->prototype('scalar')->end()
        ->end()
    ->end();
0

精彩评论

暂无评论...
验证码 换一张
取 消