sbooker / domain-events-persistence
Domain events storage
Installs: 3 213
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 1
Requires
- php: ^7.4 || ^8.0
- psr/log: ^1.0 || ^2.0 || ^3.0
- sbooker/domain-events: ^2.0
- sbooker/persistent-pointer: ^1.0
- sbooker/transaction-manager: ^2.3
- symfony/serializer: ^5.0 || ^6.0
Requires (Dev)
- gamez/ramsey-uuid-normalizer: ^2.0 || ^3.0
- phpunit/phpunit: ^9.0
- symfony/property-access: ^5.0 || ^6.0
- symfony/property-info: ^5.0 || ^6.0
- vimeo/psalm: ^4.7
Suggests
- gamez/ramsey-uuid-normalizer: ^2.0 || ^3.0
- symfony/property-access: ^5.0
- symfony/property-info: ^5.0
README
Persistence layer for sbooker/domain-events
Installation
Install via Composer:
composer require sbooker/domain-events-persistence
Usage
Publish event
See sbooker/domain-events README. Also you need configure DomainEventPreCommitProcessor
$transactionManager = new TransactionManager( new class implements TransactionHandler { ... }, new DomainEventPreCommitProcessor( new PersistentPublisher(...) ) );
Subscribe on events
<?php use Sbooker\DomainEvents\Persistence\ClassNameNameGiver; use Sbooker\DomainEvents\Persistence\PersistentEvent; $eventStorage = new class implements \Sbooker\DomainEvents\Persistence\ConsumeStorage { public function getFirstByPosition(array $eventNames,int $position): ?PersistentEvent { // ... } }; $nameGiver = new ClassNameNameGiver(); $normalizer = new class implements \Symfony\Component\Serializer\Normalizer\NormalizerInterface { /* ... */ }; use Sbooker\DomainEvents\Persistence\Consumer; $transactionManager = new \Sbooker\TransactionManager\TransactionManager( new class implements \Sbooker\TransactionManager\TransactionHandler { /* ... */ }; ); $denormalizer = new class implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface { /* ... */ }; // Own custom event handler $eventHandler = new class implements \Sbooker\DomainEvents\Persistence\PersistentEventHandler { public function handle(PersistentEvent $event) : void { // Handle Event } public function getHandledEventNames() : array { return [ /* event names as Name Giver returns */ ]; } }; // Or with Subscriber $subscriber = new class implements \Sbooker\DomainEvents\DomainEventSubscriber { public function getListenedEventClasses() : array { return [ \Sbooker\DomainEvents\DomainEvent::class ]; } public function handleEvent(\Sbooker\DomainEvents\DomainEvent $event) : void { // haddle domain event } }; $eventHandler = new \Sbooker\DomainEvents\Persistence\ConsumerSubscriberBridge( $nameGiver, $denormalizer, $subscriber ); $consumer = new Consumer( $eventStorage, $transactionManager, $eventHandler, 'subscriber.name' ); // Or all with factory $factory = new \Sbooker\DomainEvents\Persistence\ConsumerFactory( $eventStorage, $transactionManager, $nameGiver, $denormalizer ); $consumer = $factory->createBySubscriber('subscriber.name', $subscriber);
License
See LICENSE file.