You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here there is mention of the useAttributeAsKey() method, so I check this out and in the code there is a documentation against the method itself stating that:
If you'd like "'id' => 'my_name'" to still be present in the resulting
array, then you can set the second argument of this method to false.
I could argue the key would be transformed to become a map but really all that is important here (and as far as the documentation states) is that the useAttributeAsKey('some_name', false) will make sure the some_name is present in the resulting array output.
Note that there is no test for this case so I think it might have never worked or the documentation was being a little too ambitious.
So I looked into writing a test and potentially fixing this (if it were a bug). But actually while looking at the tests surrounding this method it is clear that what I expected this method to do and what is actually does is different.
I expected that when using useAttributeAsKey('name', false) and supply this:
Note that the key that key was added to the body array even though I didn't manually supply it.
Anyway after looking in to it I am good with closing this. Although I think the above might be a good feature potentially the documentation around the method (especially on the site) should be clearer.
So this might be a bug or might result in a documentation update as I find the config component documentation a little miss-leading in this area.
https://symfony.com/doc/current/components/config/definition.html#array-nodes
Here there is mention of the
useAttributeAsKey()
method, so I check this out and in the code there is a documentation against the method itself stating that:https://github.com/symfony/symfony/blob/4.0/src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php#L229-L230
So I would expect that if I take the example from the above link and set
false
against the second parameter as mentioned in the method documentation:I would expect the following output to include the
name
key:I could argue the key would be transformed to become a map but really all that is important here (and as far as the documentation states) is that the
useAttributeAsKey('some_name', false)
will make sure thesome_name
is present in the resulting array output.Note that there is no test for this case so I think it might have never worked or the documentation was being a little too ambitious.
I checked through the history (be it very quick) and this method hasn't changed since
2.8
(and probably before that but I didn't check further back). Reference can be found here https://github.com/symfony/symfony/blob/2.8/src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php#L183Anyone know if this is intended or was removed?
The text was updated successfully, but these errors were encountered: