我一直在尝试使用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']]]
答案 0 :(得分:3)
看起来我忘记了数据结构的原型:
$rootNode
->children()
->arrayNode('import')
->children()
->arrayNode('paths')
->prototype('scalar')->end()
->end()
->end()
->end()
->end();