Download the PHP package star/domain-event without Composer
On this page you can find all versions of the php package star/domain-event. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package domain-event
domain-event
Small implementation of the aggregate root in ddd.
The AggregateRoot
implementation triggers events that can be collected for publishing by an implementation of EventPublisher
.
Installation
- Add the package using composer in your
composer.json
composer require star/domain-event
Usage
-
Make your class inherit the
AggregateRoot
class. -
Create the event for the mutation.
-
Create a named constructor (static method), or a mutation method.
- Create the callback method on the
AggregateRoot
that would be used to set the state after an event mutation.
Listening to an event
When you wish to perform an operation after an event was dispatched by the EventPublisher
, you need to define your listener:
The listener needs to be given to the publisher, so that he can send the event.
Warning: Be advised that events will be removed from aggregate once collected, to avoid republishing the same event twice.
We currently support third party adapters to allow you to plug-in the library into your infrastructure.
Naming standard
The events method on the AggregateRoot
children must be prefixed with on
and followed by
the event name. ie. For an event class named StuffWasDone
the aggregate should have a method:
Note: The callback method can be changed to another format, by overriding the AggregateRoot::getEventMethod()
.
Message bus
The package adds the ability to dispatch messages (Command
and Query
). Compared to the EventPubliser
, the
CommandBus
and QueryBus
have different usages.
- Command bus: Responsible to dispatch an operation that returns nothing.
- Query bus: Responsible to fetch some information. The returned information is recommended to be returned in a readonly format.
(Example of usage)
Example
The blog example shows a use case for a blog application.
Symfony usage
Using a Symfony application, you may use the provided compiler passes to use the buses.
Once registered, three new tags will be available:
star.command_handler
star.query_handler
star.event_publisher
The tags star.command_handler
and star.query_handler
have an optional attribute message
to specify the
message FQCN that will be mapped to this handler. By default the system will try to resolve the same FQCN as the
handler, without the Handler
suffix.
Note: In both cases, omitting the message attributes would result in the same behavior.
Event store
Event stores are where your events will be persisted. You define which platform is used by extending the provided store.
Example with DBALEventStore
.
All versions of domain-event with dependencies
ext-json Version *
beberlei/assert Version ^3.3
webmozart/assert Version ^1.1