use Symfony\Component\EventDispatcher\EventDispatcher; $dispatcher = new EventDispatcher(); $dispatcher->dispatch('event.name');
use Symfony\Component\EventDispatcher\EventDispatcher; $dispatcher = new EventDispatcher(); $event = new SomeEvent($parameter); $dispatcher->dispatch('event.name', $event);
use Symfony\Component\EventDispatcher\EventDispatcher; $dispatcher = new EventDispatcher(); $dispatcher->addListener('event.name', function ($event) { // Handle the event here });
use Symfony\Component\EventDispatcher\EventDispatcher; $dispatcher = new EventDispatcher(); $dispatcher->addListener('event.name', function ($event) { // Handle the event here }, 10); // the priority is 10In all of these examples, the EventDispatcherInterface is expected to be available, which means that the Symfony\Component\EventDispatcher component or library must be installed and properly configured in the PHP project. Overall, the EventDispatcherInterface provides a simple yet powerful way to manage and handle events within a PHP application, and its usage is an important part of many Symfony-based projects.