gbprod / domain-event
Library to manage domain events in a php DDD application
Installs: 246
Dependents: 1
Suggesters: 0
Security: 0
Stars: 3
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/gbprod/domain-event
Requires (Dev)
- phpunit/phpunit: 4.*
This package is auto-updated.
Last update: 2020-06-07 07:57:05 UTC
README
Library to manage domain events in a php DDD application.
Usage
Create a domain event
<?php namespace GBProd\Acme\Event; use GBProd\DomainEvent\DomainEvent; class SomethingHappenedEvent implements DomainEvent { private $id; public function __construct($id) { $this->id = $id; } public function getAggregateId() { return $id; } }
Raise your event
<?php namespace GBProd\Acme\Entity; use GBProd\DomainEvent\EventProvider; use GBProd\DomainEvent\EventProviderTrait; final class MyEntity implements EventProvider { use EventProviderTrait; public function doSomething() { $this->raise( new SomethingHappenedEvent($this->id) ); } }
Dispatch events
<?php namespace GBProd\Acme\Repository; use GBProd\DomainEvent\EventProvider; class MyEntityRepository { public function save(MyEntity $entity) { $this->persist($entity); $this->dispatcher->dispatch($entity); } }
Requirements
- PHP 5.5+
Installation
Using composer
composer require gbprod/domain-event