Description
The useAttributeAsKey()
method seems to have an undocumented special case behavior when the argument 'name'
is passed to it.
Take this config:
foo:
bar:
a: lorem
b: ipsum
If using useAttributeAsKey('a')
, the parsed array will be
[
'foo' => [
'lorem' => [
'b' => 'ipsum'
]
]
]
If using useAttributeAsKey('name')
, then this becomes what I would expect:
[
'foo' => [
'bar' => [
'a' => 'lorem',
'b' => 'ipsum'
]
]
]
The argument 'name'
seems to have a special power here. Any other string that is not defined in the children throws an error that it’s undefined when parsing. The 'name'
seems to be implicitly created and contains the key of the YAML map.
The “fun” thing here is that if you (like me) already have a child in the array named name
, then there is no way to keep the key of the YAML map. See the following example.
foo:
bar:
name: abcd
something: lorem
This is impossible to parse and keep the bar
. The name child shadows the implicit name
that would have contained bar
. When using useAttributeAsKey('name')
, this is the result that is parsed:
[
'foo' => [
'abcd' => [
'something' => 'lorem'
]
]
]
I don't see any mention of this in the documentation of ArrayNode options. I have a PR for the documentation page I'll link to this issue, so please give that a look.