phpgears/cqrs-symfony-messenger

CQRS implementation with Symfony's Messenger

0.2.1 2019-10-05 11:34 UTC

This package is auto-updated.

Last update: 2024-11-25 07:03:08 UTC


README

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.