Skip to content

phpgears/cqrs-symfony-messenger

Repository files navigation

PHP version Latest Version License

Build Status Style Check Code Quality Code Coverage

Total Downloads Monthly Downloads

CQRS with Symfony's Messenger

CQRS implementation with Symfony's Messenger

Installation

Composer

composer require phpgears/cqrs-symfony-messenger

Usage

Require composer autoload file

require './vendor/autoload.php';

Commands Bus

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);

Query Bus

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);

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.

About

IMPLEMENTATION - CQRS with Symfony's Messenger

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages