2017 © Pedro Peláez
 

library cqrs

Infrastructure for creating CQRS applications

image

gpslab/cqrs

Infrastructure for creating CQRS applications

  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

Latest Stable Version Total Downloads Build Status Coverage Status Scrutinizer Code Quality SensioLabs Insight StyleCI License, (*1)

CQRS

Infrastructure for creating CQRS applications., (*2)

CQRS base scheme, (*3)

Installation

Pretty simple with Composer, run:, (*4)

composer require gpslab/cqrs

Command

Simple usage commands

Commands, in the CQRS approach, are designed to change the data in the application., (*5)

For example, consider the procedure for renaming an article., (*6)

Create a command to rename:, (*7)

use GpsLab\Component\Command\Command;

class RenameArticleCommand implements Command
{
    public $article_id;

    public $new_name = '';
}

Note, (*8)

To simplify the filling of the command, you can use payload., (*9)

You can use any implementations of callable type as a command handler. We recommend using public methods of classes as handlers. For example we use Doctrine ORM., (*10)

use GpsLab\Component\Command\Command;
use Doctrine\ORM\EntityManagerInterface;

class RenameArticleHandler
{
    private $em;

    public function __construct(EntityManagerInterface $em)
    {
        $this->em = $em;
    }

    public function handleRenameArticle(RenameArticleCommand $command): void
    {
        // get article by id
        $article = $this->em->getRepository(Article::class)->find($command->article_id);
        $article->rename($command->new_name);
    }
}

And now we register handler and handle command., (*11)

use GpsLab\Component\Command\Bus\HandlerLocatedCommandBus;
use GpsLab\Component\Command\Handler\Locator\DirectBindingCommandHandlerLocator;

// register command handler in handler locator
$handler = new RenameArticleHandler($em);
$locator = new DirectBindingCommandHandlerLocator();
$locator->registerHandler(RenameArticleCommand::class, [$handler, 'handleRenameArticle']);

// create bus with command handler locator
$bus = new HandlerLocatedCommandBus($locator);

// ...

// create rename article command
$command = new RenameArticleCommand();
$command->article_id = $article_id;
$command->new_name = $new_name;

// handle command
$bus->handle($command);

For the asynchronous handle a command you can use CommandQueue., (*12)

Note, (*13)

To monitor the execution of commands, you can use middleware., (*14)

Query

Simple usage queries

Query, in the CQRS approach, are designed to get the data in the application., (*15)

For example, consider the procedure for get an article by identity., (*16)

Create a query:, (*17)

use GpsLab\Component\Query\Query;

class ArticleByIdentityQuery implements Query
{
    public $article_id;
}

Note, (*18)

To simplify the filling of the query, you can use payload., (*19)

You can use any implementations of callable type as a query handler. We recommend using public methods of classes as handlers. For example we use Doctrine ORM., (*20)

use GpsLab\Component\Query\Query;
use Doctrine\ORM\EntityManagerInterface;

class ArticleByIdentityHandler
{
    private $em;

    public function __construct(EntityManagerInterface $em)
    {
        $this->em = $em;
    }

    public function handleArticleByIdentity(ArticleByIdentityQuery $query)
    {
        // get article by id
        return $this->em->getRepository(Article::class)->find($query->article_id);
    }
}

And now we register handler and handle query., (*21)

use GpsLab\Component\Query\Bus\HandlerLocatedQueryBus;
use GpsLab\Component\Query\Handler\Locator\DirectBindingQueryHandlerLocator;

// register query handler in handler locator
$handler = new ArticleByIdentityHandler($em);
$locator = new DirectBindingQueryHandlerLocator();
$locator->registerHandler(ArticleByIdentityQuery::class, [$handler, 'handleArticleByIdentity']);

// create bus with query handler locator
$bus = new HandlerLocatedQueryBus($locator);

// ...

// create find article query
$query = new ArticleByIdentityQuery();
$query->article_id = $article_id;

// handle query
$article = $bus->handle($query);

Note, (*22)

To monitor the execution of commands, you can use middleware., (*23)

License

This bundle is under the MIT license. See the complete license in the file: LICENSE, (*24)

The Versions

13/07 2017

dev-master

9999999-dev https://github.com/gpslab/cqrs

Infrastructure for creating CQRS applications

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

The Development Requires

psr-3 predis symfony cqrs infrastructure psr-11

13/07 2017
26/06 2017
23/06 2017

1.0.x-dev

1.0.9999999.9999999-dev https://github.com/gpslab/cqrs

Infrastructure for creating CQRS applications

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

The Development Requires

psr-3 predis symfony cqrs infrastructure psr-11

23/06 2017