The Symfony EventDispatcher
component is a PHP library for exchanging messages between objects. It's based on the Mediator design pattern (
https://en.wikipedia.org/wiki/Mediator_pattern
), and its implementation is relatively simple.
A very common scenario is when we have an application that we want to make extendable via plugins. In this case, we'd create a single instance of EventDispatcher
and let plugins listen to various events. Each event is an object that can hold references to other objects as well. This is what the Symfony3 framework does extensively.
If you haven't done so already, install the Event Dispatcher component via composer
:
$ composer require symfony/event-dispatcher
First, we're going to have a look at how the default implementation is used in practice, so we can later compare it to our reactive implementation, and check that both work the same from a developer's perspective while the internal...