Download the PHP package dsantang/domain-events-doctrine without Composer
On this page you can find all versions of the php package dsantang/domain-events-doctrine. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dsantang/domain-events-doctrine
More information about dsantang/domain-events-doctrine
Files in dsantang/domain-events-doctrine
Package domain-events-doctrine
Short Description Package that provides an integration with Doctrine ORM to automatically dispatch Domain Events.
License MIT
Informations about the package domain-events-doctrine
Domain Events Doctrine
This package is meant to be used in conjunction with dsantang/domain-events,
which provides the basic building blocks needed in order to create your application's domain events.
This package provides an integration with Doctrine ORM,
in order to automatically dispatch the recorded domain events once the ORM's flush()
operation is successful.
Events are dispatched via a Symfony's EventDispatcherInterface
.
Installation
The suggested installation method is via composer:
Configuration
In order to automagically dispatch your domain events, you first need to add two event listeners to your Doctrine's EventManager
.
These Doctrine's listeners will be listening to Doctrine's lifecycle events, and, only once the transaction has successfully been made,
they'll dispatch your domain events.
That's it! You're all set!
Now you can add as many Symfony's listeners as you need to your $dispatcher
,
and you'll be able to react to the domain events raised by your application.
Outbox pattern
This library also provides support for the Outbox pattern implementation.
The idea behind the implementation is to be able to add entities to an "ongoing" transaction by hooking into Doctrine's onFlush
event,
creating "outbox" entries based on the application's domain events, and safely store them using the same DB transaction.
In order to enrich your Domain Event and be able to set all the data required by the Outbox entity,
you need to create a Converter
class (by implementing Dsantang\DomainEventsDoctrine\Outbox\Converter
interface)
An example of an outbox event is as follows:
In order to persist your Outbox entries, you must create a Doctrine Entity class inside your application that extends
Dsantang\DomainEventsDoctrine\Outbox\OutboxMappedSuperclass
.
Please note that this approach uses Doctrine's Inheritance Mapping:
Here is an example of an Outbox Entity class:
And an example of the required configuration as is follows:
Warning: this solution assumes that you're using Dsantang\DomainEvents\DomainEvent
in order to raise your domain events.
All versions of domain-events-doctrine with dependencies
doctrine/dbal Version ^3.5
doctrine/orm Version ^2.8
dsantang/domain-events Version ^0.5
ramsey/uuid Version ^4.1
symfony/event-dispatcher Version ^5.2
symfony/event-dispatcher-contracts Version ^2.4