Release 2.1.1
Changelog (since 2.1.0...2.1.1
)
-
Added ability to subscribe to events.
use GpsLab\Domain\Event\Event; use GpsLab\Domain\Event\Listener\Subscriber; class SendEmailOnPurchaseOrderCreated implements Subscriber { private $mailer; public function __construct(\Swift_Mailer $mailer) { $this->mailer = $mailer; } public static function subscribedEvents() { return [ PurchaseOrderCreatedEvent::class => ['onPurchaseOrderCreated'], ]; } public function onPurchaseOrderCreated(PurchaseOrderCreatedEvent $event) { $message = $this->mailer ->createMessage() ->setTo('recipient@example.com') ->setBody(sprintf( 'Purchase order created at %s for customer #%s', $event->getCreateAt()->format('Y-m-d'), $event->getCustomer()->getId() )); $this->mailer->send($message); } }
Register event subscriber
services: acme.domain.purchase_order.event.created.send_email_subscriber: class: SendEmailOnPurchaseOrderCreated arguments: [ '@mailer' ] tags: - { name: domain_event.subscriber }