antismok / domain-events-publisher
Publisher of domain events implemented on symfony dispatcher component
Installs: 9 263
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^7.1
- symfony/event-dispatcher: *
Requires (Dev)
- phpunit/phpunit: ^7.4
This package is auto-updated.
Last update: 2024-09-08 15:56:35 UTC
README
Publisher of immutable domain events implemented on symfony dispatcher component.
See https://symfony.com/doc/current/components/event_dispatcher.html
Usage
//.... use Antismok\DomainEventPublisher\DomainEvent; class UserRegistered implements DomainEvent { private $occurredOn; /** * @var string $user */ private $userName; /** * @param string $userName */ function __construct(string $userName) { $this->useName = $userName; $this->occurredOn = new DateTime(); } public function username(): string { return $this->username; } public function occurredOn(): DateTime { return $this->occurredOn; } }
//.... class UserRegisteredHandler { public function handle(UserCreated $event) { //Some operation } }
//.... //Some config place DomainEventPublisher::getInstance()->addListener(UserRegistered::class, [new UserRegisteredHandler, 'handle']); //Some domain place DomainEventPublisher::getInstance()->publish(new UserRegistered('Roman'));