CQRS implementation with League Tactician
composer require phpgears/cqrs-tactician
Require composer autoload file
require './vendor/autoload.php';
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);
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);
Found a bug or have a feature request? Please open a new issue. Have a look at existing issues before.
See file CONTRIBUTING.md
See file LICENSE included with the source code for a copy of the license terms.