Skip to content

Latest commit

 

History

History
26 lines (18 loc) · 1.17 KB

Event.md

File metadata and controls

26 lines (18 loc) · 1.17 KB

Event System

As Greg Young (and many others) says: "An event is something that happened, it's in the past".

The Event system allows you to act on what happened on your application.
It is thrown by the Domain (Aggregate roots).

It has many uses:

  • send an email to a user when he subscribes to your website
  • log every things that happened to your application
  • do something on other aggregate roots when another BoundedContext changes its states
  • ...

The main advantages over classic development is that everything is bound to something inside your Domain application.

How it works

  1. Configuring the EventDispatcher
  2. Create an Event class (extending PhpDDD\DomainDrivenDesign\Event\AbstractEvent) - example
  3. Create an EventSubscriber (implementing PhpDDD\DomainDrivenDesign\Event\EventSubscriberInterface) - example
  4. Attach your EventSubscriber to the EventDispatcher (you may need to instantiate it)
  5. Publishing
  6. instantiate your Event
  7. publish it ($eventDispatcher->publish(new Event());)