Download the PHP package smartgecko/governor-framework without Composer
On this page you can find all versions of the php package smartgecko/governor-framework. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download smartgecko/governor-framework
More information about smartgecko/governor-framework
Files in smartgecko/governor-framework
Package governor-framework
Short Description PHP Command-Query-Responsibility-Segregation framework.
License MIT
Informations about the package governor-framework
Governor Framework PHP CQRS library
Governor Framework is a Command and Query Responsibility Segregation library for PHP 5.5+.
It provides components to build applications following the CQRS patterns such as:
- Command Handling
- Event Handling
- Event Sourcing
- Event Stores
- Sagas
- Unit Of Work
- Repositories
- Serialization
- AMQP support
- Testing
The main source of inspiration for this library was the Axon Framework written in Java and the Governor Framework can be viewed as a PHP port of the Axon, because it retains its basic building blocks.
The library can be directly integrated into the Symfony 2 framework as a bundle. The core of the Symfony 2 integration was taken from the LiteCQRS framework.
Quick Start
The Domain Model
To demonstrate the features of the Governor Framework we will work with a rather simple User model. The User class is our aggregate root. Aggregate roots in Governor must either implement the interface or extend one of the built in base classes:
In this example we will use the aggregate root with annotation support. Our aggregate will also serve as a command handler in this example.
The aggregate will react to the commands
which will produce the corresponding events
Our aggregate root implementation will look the following.
Commands and Events
We introduce 2 operations over the aggregate - one will create a new user and the second will change the user email. Notice the annotations on the event class - Governor Framework uses the excellent JMS serializer library for serialization and deserialization purposes. To allow event deserialization when rebuilding the aggregate from an event stream the annotations must be present in order to successfully deserialize the events.
Our commands and events are implemented like this:
Event listeners
We can register event listeners to listen for events on the event bus. The event listeners need to implement the interface.
This simple listener that will listen for all events on the event bus and print their payload.
Wrapping it all together
Now we can complete the example by setting up the necessary infrastructure in the following steps
- We need to set up a PSR-0 compatible logger like Monolog.
- Create a command bus and for convienience wrap it in a command gateway.
- Initialize an event store backed by a filesystem. Note that if you don't want to use event sourcing this step can be skipped.
- Set up a simple event bus
- Create an event sourcing repository
- Subscribe the annotated aggregate root to the command bus so it can recieve commands.
- Register an event listener that will display the content of our events.
- Dispatch commands.
Licensing
Governor Framework is licensed under the MIT license.
All versions of governor-framework with dependencies
psr/log Version @stable
php Version 5.5.*
symfony/proxy-manager-bridge Version >=2.4
ocramius/proxy-manager Version 0.5.*
monolog/monolog Version 1.8.0
hamcrest/hamcrest-php Version v1.1.1
videlalvaro/php-amqplib Version 2.2.*
predis/predis Version *
jms/serializer Version *