1

I want to parse a config of this structure:

$config = [
    'streams' => [
        'foo' => [
            [
                'id' => 'some-identifier',
                'type' => 'a',
            ],
            [
                'id' => 'some-other-identifier',
                'type' => 'b',
            ],
        ],
        'bar' => ...,
    ],
];

In this array streams is a predefined key and contains a map of multiple arbitrarily named streams. In this case there are two streams called foo and bar defined.

Every stream has an array of handlers. Every handler is a map with 2 attributes: id and type.

I ended up with:

$rootNode
    ->children()
        ->arrayNode('streams')
            ->prototype('array')
                ->children()

                ->end()
            ->end()
        ->end()
    ->end()
;

And now I'm in stuck on what would be next.

If I explain in English it would be: streams is a map of arrays of maps.

And with my code I could express it up to "is a map" and in stuck how to say it's "of arrays".

Any hints?

1 Answer 1

3

That's how.

$rootNode
    ->children()
        ->arrayNode('streams')
            ->prototype('array')
                ->prototype('array')
                    ->children()
                        ->scalarNode('id')->end()
                        ->scalarNode('type')->end()
                    ->end()
                ->end()
            ->end()
        ->end()
    ->end()
;

Note that the outer prototype('array') does not have children()

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.