Download the PHP package cvek/domain-events without Composer
On this page you can find all versions of the php package cvek/domain-events. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package domain-events
Domain events bundle for Symfony
The bundle integrates with Symfony application to provide domain events support. This allows to be doctrine-agnostic and raise events during the business logic implementation.
Domain events are of three types:
preFlush
. Will be processed synchronously before persisting to DB;onFlush
. Will be processed during persisting to DB (sync or async - see below);postFlush
. Will be processed after persisting to DB (sync or async - see below).
To use this bundle implement RaiseEventsInterface
interface in your entity class and create your custom domain events. We recommend you to use RaiseEventsTrait
to simplify this even more.
Sync/Async messages
Any domain event can be executed in a sync
or an async
way during onFlush
and postFlush
Doctrine events. Extend one of abstract classes: AbstractSyncDomainEvent
or AbstractAsyncDomainEvent
to have sync
or async
event respectively.
Async way is a very powerful approach and must be used in the following cases:
- you want to postpone some time-consuming or remote tasks;
- you want to avoid restrictions of Doctrine event system (e.g. see this and this).
Thanks to db
transport with doctrine storage (will be created automatically) - all the async domain events will be routed and persisted to db automatically.
To consume them we recommend to use the following supervisor config:
:warning: Dont forget to add it to your application!
Direct Async message
If you dont want to write your own async message handler, but dispatch your message directly, then simply extend AbstractDirectAsyncDomainEvent
in your message and use it this way:
The message will be dispatched directly to bus, without of need to write your own handler.
Example
Install
composer req cvek/domain-events
Use
Create domain event
Sync event
Async event
Raise event in your business layer
Catch event in listener
When flush
operation will be invoked, all the events, raised in your entities, will be collected and dispatched. You can listen on them in a usual manner.
Listen on sync message
Listen on async message
All versions of domain-events with dependencies
symfony/config Version ^4.0|^5.0|^6.0
symfony/dependency-injection Version ^4.0|^5.0|^6.0
symfony/http-kernel Version ^4.0|^5.0|^6.0
symfony/event-dispatcher Version ^4.0|^5.0|^6.0
symfony/doctrine-bridge Version ^4.0|^5.0|^6.0
doctrine/orm Version ^2.0
symfony/messenger Version ^4.0|^5.0|^6.0