You can handle many events in one subscriber.
class PurchaseOrderSubscriber implements Subscriber
{
public static function subscribedEvents()
{
return [
PurchaseOrderCreatedEvent::class => ['handlePurchaseOrderCreated'],
PurchaseOrderCompletedEvent::class => ['handlePurchaseOrderCompleted'],
];
}
public function handlePurchaseOrderCreated(PurchaseOrderCreatedEvent $event)
{
// do something
}
public function handlePurchaseOrderCompleted(PurchaseOrderCompletedEvent $event)
{
// do something
}
}
$listener = new PurchaseOrderListener();
// register event listener in listener locator
$locator = new DirectBindingEventListenerLocator();
$locator->registerSubscriber(new PurchaseOrderSubscriber());
You can use exists locators of listener:
Or you can create custom locator that implements GpsLab\Domain\Event\Listener\Locator\EventListenerLocator
interface.