Download the PHP package bornfreee/tactician-domain-events-bundle without Composer
On this page you can find all versions of the php package bornfreee/tactician-domain-events-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package tactician-domain-events-bundle
Tactician Domain Events Symfony Bundle
Symfony Bundle to integrate Tactician Domain Events library with Symfony project
Installation
Install via composer
Add bundle to AppKernel.php
:
Configuration
On default event collector CollectsEventsFromEntities
will be used, but sometimes you might record an event when entity doesn't change so the event is not collected.
It's also true when an aggregate root is recording events for its child entities. To collect those events you need to use CollectsEventsFromAllEntitiesManagedByUnitOfWork
That one collects events from all entities which are managed by Unit of Work. To use it you need to set collect_from_all_managed_entities
on true:
Usage
This bundle allows you to automatically have Domain Events dispatched by EventDispatcher
. It also allows to register event listeners and subscribers as the Symfony Services.
You can register as many listeners as you want for each Domain Event.
First, we need to install the Tactician official Bundle to integrate the command bus library:
Then we need to configure Middleware to automatically record the Domain Events and dispatch them. We only want to handle the events themselves after the command has completely and successfully been handled. So we add the middleware that records the Domain Events before the Transaction middleware.
It means that as soon as transaction is completed, the Domain Events will be recorded:
Configuring Event Listeners
In order to add event listeners for dispatched Domain Events, we need to define services and the corresponded commands for them:
Notice the tag tactician.event_listener
. The bundle automatically finds all services tagged with this tag and adds the listener to EventDispatcher
.
By default, event listener shold have public __invoke
function. If you want to have regular method name, it's possible to it to the service configuration:
This is all configuration you need to start using the Tactician command bus with Domain Events.
Let's have an example where we create a new user and a UserWasCreated
domain event is dispatched:
As soon as this Entity
is successfully created, the SendEmailAfterUserIsCreatedListener
will be triggered.
Debugging
You can run the debug:tactician-domain-events
command to get a list of all events with mapped listeners.
License
Copyright (c) 2017, Maks Rafalko
Under MIT license, read LICENSE file.
All versions of tactician-domain-events-bundle with dependencies
symfony/config Version ^2.8|^3.0|^4.0|^5.0
symfony/http-kernel Version ^2.8|^3.0|^4.0|^5.0
symfony/dependency-injection Version ^2.8|^3.0|^4.0|^5.0
bornfree/tactician-doctrine-domain-events Version ^0.4.0