Closed prudloff-insite closed 3 years ago
Thanks for the PR.
Not sure what the added useAttributeAsKey()
does in this case.
If I read the docs correctly, it promotes an attribute in the child object as the name of the task.
But we don't have a name property + the content of the task is variable.
Can you point me in the right direction on this topic so that I can make a better decision on this PR?
useAttributeAsKey()
is indeed primarily used to tell the config loader to use an attribute as the array key.
But it also has the side effect of making the config loader aware that the key has meaning and should not be dropped.
Without this, mergeValues()
will drop the key here (because it thinks it is irrelevant): https://github.com/symfony/config/blob/a923cd33330f10d906dd9348f99f45992e61fbcb/Definition/PrototypedArrayNode.php#L305
However, the attribute does not have to be set, as normalizeValue()
will take the existing key if the key attribute is null.
So this:
tasks:
composer: ~
And this:
tasks:
foo:
name: composer
Will have the same meaning after this patch is applied.
Meaning that if there is a task out there with the "name" property, it will break the system? If we are abusing this side-effect, isn't there a way to do the side effect without the main effect? (if that makes sense :) )
I used name
but we could use a more specific attribute.
I found an upstream issue about this and this comment seems to confirm useAttributeAsKey()
is the correct way to do this: https://github.com/symfony/symfony/issues/18988#issuecomment-224234613
We have two separate YAML files like this:
This does not work because the import does not merge the task array correctly. If I dump it, the merged array looks like this:
And it will crash with this error:
This PR makes sure the keys are kept when merging the arrays.