3

I want to process the following configuration:

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

It is clear that I will need to add an arrayNode, like

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

but this gives me an InvalidConfigurationException with the message

Unrecognized options "transitions" under "acme_demo.state_machine"

How should I process those "inner" values?

1 Answer 1

3

A large amount of stress after hours of trying drove me to the solution just after writing down the question:

$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()
    ;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.