gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 20:54:11 25 4
gpt4 key购买 nike

我实际上正在开发一个 symfony 2 包。我希望允许用户使用 DIC 配置我的包,而无需检查包配置的某些部分。

例如,用户设置此配置:

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

我的配置包是这样设置的:
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('root_node');

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

我希望“节点”的子节点可以由用户配置,而无需检查捆绑配置。我不知道如何修改此问题的配置。

最佳答案

在 symfony2 github 存储库上进行了一些研究后,我找到了解决方案。对于其他想做同样事情的人,解决方案是:

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

关于dependency-injection - SF2 : Allow user to configure bundle without checking some part of the bundle configuration,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6557716/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com