fesor / domain-events
Simple domain events implementation
Installs: 14 224
Dependents: 0
Suggesters: 0
Security: 0
Stars: 32
Watchers: 6
Forks: 1
Open Issues: 0
Requires (Dev)
- fabpot/php-cs-fixer: ^1.9
- phpspec/phpspec: ^2.2
This package is not auto-updated.
Last update: 2024-10-30 09:28:18 UTC
README
This is very simple implementation of domain events.
Usage
<?php namespace Domain\User; use \Fesor\DomainEvent\DomainEvents; class User { use DomainEvents; private $email; private $password; public function __constructor(Email $email, Password $password) { $this->email = $email; $this->password = $password; // remember event $this->rememberThat(new UserRegistered($this)); } }
Now we can know what happened with our entity during request:
$user = new User(new Email($email), new Password($password)); $events = $user->releaseEvents(); // will return array with UserRegistered event $tryAgain = $user->releaseEvents(); // will return empty array, since we already released all events $dispatcher = new EventDispatcher(); $dispatcher->dispatch($events);