PHP code example of sbooker / domain-events-persistence
1. Go to this page and download the library: Download sbooker/domain-events-persistence library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
sbooker / domain-events-persistence example snippets
$transactionManager = new TransactionManager(
new class implements TransactionHandler { ... },
new DomainEventPreCommitProcessor(
new PersistentPublisher(...)
)
);
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);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.