use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\EventDispatcher\EventDispatcherInterface; $dispatcher = new EventDispatcher(); $dispatcher->addListener('eventName', function ($event) { // Do something when the event 'eventName' is dispatched }); $dispatcher->dispatch('eventName', new Event());
use Symfony\Component\EventDispatcher\Event; class MyEvent extends Event { // ... } $dispatcher->dispatch('eventName', new MyEvent());In this example, a custom event class "MyEvent" is created and dispatched to the event dispatcher with the event name "eventName". Any event listeners listening for "eventName" will be executed with the "MyEvent" instance as its argument. This package library is Symfony's EventDispatcher component.