Symfony配置树构建器

时间:2016-09-21 08:03:23

标签: php configuration symfony

我一直在尝试使用Symfony 3进行树构建器配置来解析这样的配置:

my_bundle:
    import:
        paths:
            - 'some/path'
            - 'another/path'

My TreeBuilder看起来像这样:

$rootNode
    ->children()
        ->arrayNode('import')
            ->children()
                ->arrayNode('paths')
                    ->addDefaultsIfNotSet()
                    ->defaultValue([])
                    ->cannotBeEmpty()
                ->end()
            ->end()
        ->end()
    ->end();

它基本上就像我希望得到的二维数组配置。你能帮帮我解决一下吗?

预期解析配置:

['import' => ['paths' => ['some/path', 'another/path']]]

1 个答案:

答案 0 :(得分:3)

看起来我忘记了数据结构的原型:

$rootNode
    ->children()
        ->arrayNode('import')
            ->children()
                ->arrayNode('paths')
                    ->prototype('scalar')->end()
                ->end()
            ->end()
        ->end()
    ->end();