EventDispatch implements the Mediator pattern, not the Observer pattern #2817
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Anthony Ferrara @ircmaxell does a great job of pointing out the differences between the Mediator and Observer pattern in his blog post Handling Plugins In PHP.
The two patterns appear very similar but differ in which object does the event emitting:
An implementation of the Observer pattern would allow each object/entity/service to individually allow subscribing to its events and it would notify all listeners itself:
OrderPersister->notify('order.create', $order)
But a Mediator pattern implementation would be like the Symfony EventDispatcher object that is centrally-configured with listeners and then notifies those listeners of events on behalf of its external collaborators: Inside a controller
$this->persister->create($order);
then inside Persister::create() --$this->dispatcher->notify('order.create', $order)
🌊