neos / flow-development-collection

The unified repository containing the Flow core packages, used for Flow development.
https://flow.neos.io/
MIT License
138 stars 188 forks source link

Extending array values in settings with anonymous keys ("-") is not safe #555

Open neos-bot opened 10 years ago

neos-bot commented 10 years ago

Jira issue originally created by user @hlubek:

It is not safe to add an entry to an array setting by using "-" for the key, e.g.:

    persistence:
      doctrine:
        eventListeners:
          -
            events: ['postPersist', 'postUpdate', 'postRemove']
            listener: 'TYPO3\Neos\Domain\EventListener\AccountPostEventListener'

If a second package does the same, this will end up in only one event listener, which will be overridden by the second one. This happened at least with the phpyaml extension being used to parse YAML files.

Jira-URL: https://jira.neos.io/browse/FLOW-22

neos-bot commented 10 years ago

Comment created by @kitsunet:

But this is then rather a problem in our merge algorithm if it came from two differnt files.

neos-bot commented 10 years ago

Comment created by @hlubek:

@Christian: It depends where we want fix it. The safest thing would be to change anonymous array keys to a named key in the default configuration. This way there won't be any index collisions.

The other idea (with backwards compatibility problems) would be to extend the merge algorithm to handle numeric keys in a special way. But I'm not too sure about the consequences and how we want to control the merging behavior. E.g. sometimes you want to extend an array value with a new item (as in the eventListeners case above) and sometimes you might want to replace a value completely (as for the events setting).

neos-bot commented 10 years ago

Comment created by @kitsunet:

I don't think that is a solution we can apply to all anonymous keys... What I meant is that each yaml file is parsed separate and then merged, so I don't see how this could be a problem of the parser (unless one creates the numerical index as strings and the other doesn't or something like that) but basically looking at the code we have a problem with that because we always merge keys. I think we had the discussion again but for numerically indexed arrays we should rather append... Problem is how to detect the difference.