CQRS PHP
CQRS in PHP is a simple project (a folder structure) for your project build with Domain Driven Design., (*1)
, (*2)
Installation
The recomanded way to install CQRS in PHP is through Composer:, (*3)
{
"require": {
"black/cqrs-php": "@stable"
}
}
Protip: You should browse the black/cqrs-php
page to choose a stable version to use, avoid the @stable
meta
constraint., (*4)
Why?
I want to use a very basic library for CQRS without Event Sourcing.
There is one Bus, register your handler with the related command and go for it!, (*5)
Usage
1 - Create a Command implementing Black\DDD\CQRSinPHP\Infrastructure\CQRS\Command
2 - Create an Handler implementing Black\DDD\CQRSinPHP\Infrastructure\CQRS\CommandHandler
3 - Register the Handler/Command to the Bus, (*6)
<?php
$bus = new Black\DDD\CQRSinPHP\Infrastructure\CQRS\Bus;
$handler = new My\Handler();
$bus->register('My\Command', $handler);
// Do stuff
$command = new My\Command($foo, $bar);
$bus->handle($command);
SymfonyBundle
Register the bundle:, (*7)
``` php
<?php
// app/AppKernel.php, (*8)
public function registerBundles()
{
$bundles = array(
// ...
new Black\Bundle\CQRSBundle\BlackCQRSBundle(),
);
}, (*9)
Declare your handler as a service and add this tag:
```yaml
services:
my.handler:
class: 'My\Handler'
tags:
- { name: black_cqrs.handler, command: "My\Command" }
And use it:, (*10)
<?php
public function __construct(Black\DDD\CQRSinPHP\Infrastructure\CQRS\Bus $bus)
{
$this->bus = $bus;
}
public function myFunction($foo, $bar)
{
$command = new My\Command($foo, $bar);
$this->bus->handle($command);
}
Contributing
This project is a work in progress so don't hesitate to see CONTRIBUTING file and submit your PR., (*11)
Credits
The code is heavily inspired by Benjamin Eberlei blog posts who did a very great job on many projects (including
Doctrine and litecqrs-php., (*12)
This README is heavily inspired by Hateoas library by the great @willdurand.
This guy needs your PR for the sake of the REST in PHP., (*13)
Alexandre "pocky" Balmes alexandre@lablackroom.com.
Send me Flattrs if you love my work, buy me gift
or hire me!, (*14)
License
CQRS in PHP
is released under the MIT License. See the bundled LICENSE file for details., (*15)