blacksmith-project / event-manager
A PHP library providing event tools
Installs: 42
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/blacksmith-project/event-manager
Requires (Dev)
- escapestudios/symfony2-coding-standard: ^3.9
- mnapoli/pretty: ^1.0
- phpstan/phpstan: ^0.11.15
- phpunit/phpunit: ^8.3
- squizlabs/php_codesniffer: ^3.4
This package is auto-updated.
Last update: 2020-03-07 11:55:42 UTC
README
A PHP Library providing tools to manage Events in Domain Driven Design.
How to use it
Make your Entity implements \BSP\EventManager\IRegisterEvent and use \BSP\EventManager\EventRegistration.
Your Entity can now contain its own events.
Example:
class Entity implements IRegisterEvent { use EventRegistration; private $id; private function __construct(UuidInterface $id) { $this->id = $id; } public static method Register(UuidInterface $id): self { $entity = new self($id); $this->recordedEvents[] = new EntityRegistered($id); return $entity; } }
You now have access to $entity->recordedEvents(), and can loop on those, to dispatch them for example.
Then, you can call $entity->clearRegisteredEvents() to clear them off.