gpt4 book ai didi

Symfony 2 - 配置值 : array of associative arrays

转载 作者:行者123 更新时间:2023-12-02 14:24:56 27 4
gpt4 key购买 nike

我想处理以下配置:

acme_demo:
transitions:
- { hc_cba: 180 }
- { cba_hc: -1 }

很明显,我需要添加一个 arrayNode,例如

$rootNode
->children()
->arrayNode('transitions')
->beforeNormalization()
->ifArray()
->then(function($values) {
return array('transition' => $values);
})
->end()
->end()
->end()
->end()
;

但这给了我一个带有消息的 InvalidConfigurationException

Unrecognized options "transitions" under "acme_demo.state_machine"

我应该如何处理这些“内在”值(value)观?

最佳答案

经过几个小时的尝试后,巨大的压力促使我在写下问题后找到了解决方案:

$rootNode
->children()
->arrayNode('state_machine')
->requiresAtLeastOneElement()
->beforeNormalization()
->ifArray()
->then(function($values) {
$ret = array();

foreach ($values as $value) {
foreach ($value as $transition => $time) {
$ret[] = array('transition' => $transition, 'time' => e);
}
}

return $ret;
})
->end()
->prototype('array')
->children()
->scalarNode('transition')->end()
->scalarNode('time')->end()
->end()
->end()
->end()
->end()
;

关于Symfony 2 - 配置值 : array of associative arrays,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13923892/

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