3

我想处理以下配置:

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"

我应该如何处理那些“内在”价值?

4

1 回答 1

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()
    ;
于 2012-12-17T23:32:59.183 回答