RFC: Event focused extension system #3489
Replies: 4 comments 2 replies
-
Hi I really get the advantages regarding the compatibility. In HEPTAconnect we decided to have a payload/params object, that can be extended at any point to keep service decoration flexible. We took the inspiration from event handlers from .NET though :D Today I just wrote a service decorator and that is why I went here to this discussion. The decorator basically looks like this:
And this is something I cannot do with events but it is something I (have to) do regularly. |
Beta Was this translation helpful? Give feedback.
-
Also something, that we sometimes do is to remove decorators because they are not what we need in a project. Removing a decorator is easy. Drop the service definition. Removing a single event listener is not very easy. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
I noticed one thing today that doesn't exist in an event-based approach: Naming collisions. I just added a function into the MigrationStep called addColumn... If someone else already has such a function, it crashes. In itself, adding a protected (or private) function in one of our classes wouldn't be a break. And i could release this inside a patch release. However, if third-party "plugins" extend this class, collisions can occur, resulting in fatal PHP errors during the update of a patch release :/ . |
Beta Was this translation helpful? Give feedback.
-
Description
Currently, there are discussions about moving away from decoration over services and creating a "unified" extension system.
At present, we have services, tagged services, interfaces, adapters, events, etc.
Therefore, in the entire "Better software" discussion, the idea has emerged to enable more through events.
In Shopware 5, there were various events for different situations:
Hence, I've been considering whether we could replace our service decoration with an event approach. In doing so, I designed this system.
In my opinion, this system has some advantages:
In this context, I would also want to enforce reference documentation, in which all of these extension points must already be provided with tests + API reference documentation. (Ensured via a PHP Stan rule).
Of course, service decoration is still possible in projects, but we would only officially communicate this way. But I would like to replace interfaces and abstract classes and only define this path for PHP extensions.
I would be happy to hear your opinion on this topic.
I implemented a POC for it, which you can checkout and test.
Specification
Definition of an extension
The extension dispatcher
How we call it
For more details, take a look into the linked merge request
Merry Christmas and a Happy New Year 🎄 🥳
Beta Was this translation helpful? Give feedback.
All reactions