CQRS implementation with Symfony's Messenger
composer require phpgears/cqrs-symfony-messenger
Require composer autoload file
require './vendor/autoload.php';
use Gears\CQRS\Symfony\Messenger\CommandBus;
use Gears\CQRS\Symfony\Messenger\CommandHandlerLocator;
use Symfony\Component\Messenger\MessageBus;
use Symfony\Component\Messenger\Middleware\HandleMessageMiddleware;
$commandToHandlerMap = [];
$messengerBus = new MessageBus([
new HandleMessageMiddleware(new CommandHandlerLocator($commandToHandlerMap)),
]);
$commandBus = new CommandBus($messengerBus);
/** @var \Gears\CQRS\Command $command */
$commandBus->handle($command);
use Gears\CQRS\Symfony\Messenger\QueryBus;
use Gears\CQRS\Symfony\Messenger\QueryHandlerLocator;
use Symfony\Component\Messenger\MessageBus;
use Symfony\Component\Messenger\Middleware\HandleMessageMiddleware;
$queryToHandlerMap = [];
$messengerBus = new MessageBus([
new HandleMessageMiddleware(new QueryHandlerLocator($queryToHandlerMap)),
]);
$queryBus = new QueryBus($messengerBus);
/** @var \Gears\CQRS\Command $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.