<?php
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\GenericEvent as Event;
// all event listeners
$eventListener1 = function (Event $event) {
echo 'Call me' . PHP_EOL;
};
$eventListener2 = function (Event $event) {
echo 'Call me too' . PHP_EOL;
};
$eventListener3 = function (Event $event) {
echo 'Call me three' . PHP_EOL;
};
// add listeners to EventDispatcher
$dispatcher = new EventDispatcher();
$dispatcher->addListener('callme', $eventListener1);
$dispatcher->addListener('callmetoo', $eventListener2);
$dispatcher->addListener('callme', $eventListener3);
// we only want $eventListener1 and $eventListener3
$dispatcher->dispatch(new Event(), 'callme');