black/cqrs-php

This package is abandoned and no longer maintained. No replacement package was suggested.
There is no license information available for the latest version (v1.0.2) of this package.

Implements CQRS (for DDD in PHP)

v1.0.2 2014-10-22 21:32 UTC

This package is not auto-updated.

Last update: 2020-05-08 14:08:54 UTC


README

CQRS in PHP is a simple project (a folder structure) for your project build with Domain Driven Design.

Latest Stable Version Total Downloads

Installation

The recomanded way to install CQRS in PHP is through Composer:

{
    "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.

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!

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

<?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:

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Black\Bundle\CQRSBundle\BlackCQRSBundle(),
    );
}

Declare your handler as a service and add this tag:

services:
    my.handler:
        class: 'My\Handler'
        tags:
            - { name: black_cqrs.handler, command: "My\Command" }

And use it:

<?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.

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.

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.

Alexandre "pocky" Balmes alexandre@lablackroom.com. Send me Flattrs if you love my work, buy me gift or hire me!

License

CQRS in PHP is released under the MIT License. See the bundled LICENSE file for details.