I want to create a configuration like:
root_node:
static_key:
dynamic_key_1: [array, of, values]
dynamic_key_2: [array, of, values]
I cannot imagine the correct Treebuilder syntax.
I tried:
$rootNode
->children()
->arrayNode('static_key')
->prototype('scalar')
->end()
->end()
->end()
;
but I get:
Invalid type for path "root_node.static_key.dynamic_key_1". The expected scalar, but the resulting array.
and when I switch to:
$rootNode
->children()
->arrayNode('static_key')
->prototype('array')
->end()
->end()
->end()
;
I get:
Unrecognized options "0, 1, 2" in the section "root_node.static_key.dynamic_key_1"
In the end, I realized that I could go through the configuration pass using:
$rootNode
->children()
->arrayNode('static_key')
->prototype('variable')
->end()
->end()
->end()
;
but this does not guarantee an array.
Can someone point me in the right direction?
I know I can do something like this:
$rootNode
->children()
->arrayNode('static_key')
->prototype('array')
->children()
->scalarNode('attr_1')->end()
->scalarNode('attr_2')->end()
->end()
->end()
->end()
->end()
;
root_node:
static_key:
dynamic_key_1:
attr_1: value_1
attr_2: value_2
dynamic_key_2: {attr_1: value_3, attr_2: value_4}
and get the following PHP array:
array('root_node' => array(
'static_key' => array(
'dynamic_key_1' => array(
'attr_1' => 'value_1',
'attr_2' => 'value_2'
),
'dynamic_key_2' => array(
'attr_1' => 'value_3',
'attr_2' => 'value_4'
),
),
));
I have done this before.
I just know why I cannot strictly request a non-associative array:
{attr_1: value_3, attr_2: value_4} vs [value_3, value_4]? : , - .