Skip to content

Latest commit

 

History

History
43 lines (33 loc) · 1.19 KB

subscriber.md

File metadata and controls

43 lines (33 loc) · 1.19 KB

Event subscriber

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());

Listener locator

You can use exists locators of listener:

Or you can create custom locator that implements GpsLab\Domain\Event\Listener\Locator\EventListenerLocator interface.