我想处理以下配置:
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()
;
但是这给了我带有消息
的InvalidConfigurationExceptionUnrecognized options "transitions" under "acme_demo.state_machine"
我应该如何处理这些“内在”价值观?
答案 0 :(得分:3)
在写下这个问题之后,经过数小时尝试后的大量压力驱使我找到解决方案:
$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()
;