phpgears/cqrs-tactician

CQRS implementation with League Tactician

0.4.1 2019-10-05 11:29 UTC

This package is auto-updated.

Last update: 2024-10-25 06:36:20 UTC


README

PHP version Latest Version License

Build Status Style Check Code Quality Code Coverage

Total Downloads Monthly Downloads

CQRS with Tactician

CQRS implementation with League Tactician

Installation

Composer

composer require phpgears/cqrs-tactician

Usage

Require composer autoload file

require './vendor/autoload.php';

Commands Bus

use Gears\CQRS\Tactician\CommandBus;
use Gears\CQRS\Tactician\CommandHandlerMiddleware;
use League\Tactician\CommandBus as TacticianBus;
use League\Tactician\Handler\Locator\InMemoryLocator;
use League\Tactician\Plugins\LockingMiddleware;

$commandToHandlerMap = [];
        
$tacticianBus = new TacticianBus([
    new LockingMiddleware(),
    new CommandHandlerMiddleware(new InMemoryLocator($commandToHandlerMap)),
]);

$commandBus = new CommandBus($tacticianBus);

/** @var \Gears\CQRS\Command $command */
$commandBus->handle($command);

Query Bus

use Gears\CQRS\Tactician\QueryBus;
use Gears\CQRS\Tactician\QueryHandlerMiddleware;
use League\Tactician\CommandBus as TacticianBus;
use League\Tactician\Handler\Locator\InMemoryLocator;
use League\Tactician\Plugins\LockingMiddleware;

$queryToHandlerMap = [];
        
$tacticianBus = new TacticianBus([
    new LockingMiddleware(),
    new QueryHandlerMiddleware(new InMemoryLocator($queryToHandlerMap)),
]);

$queryBus = new QueryBus($tacticianBus);

/** @var \Gears\CQRS\Query $query */
$result = $queryBus->handle($query);

Contributing

Found a bug or have a feature request? Please open a new issue. Have a look at existing issues before.

See file CONTRIBUTING.md

License

See file LICENSE included with the source code for a copy of the license terms.