chimera / bus-tactician
Service bus adapter for league/tactician
Installs: 119 206
Dependents: 1
Suggesters: 1
Security: 0
Stars: 3
Watchers: 4
Forks: 0
Open Issues: 9
Requires
- php: ^7.4 || ^8.0
- chimera/foundation: ^0.4
- league/tactician: ^1.1
- psr/container: ^1.0
Requires (Dev)
- infection/infection: ^0.21
- lcobucci/coding-standard: ^6.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan: ^0.12
- phpstan/phpstan-deprecation-rules: ^0.12
- phpstan/phpstan-phpunit: ^0.12
- phpstan/phpstan-strict-rules: ^0.12
- phpunit/phpunit: ^9.5
Provides
- chimera/bus-implementation: 0.4.0
- 1.0.x-dev
- 0.4.x-dev
- 0.4.0
- 0.3.0
- 0.2.0
- 0.1.0
- dev-renovate/test-packages
- dev-renovate/all-minor-patch
- dev-renovate/codecov-codecov-action-5.x
- dev-renovate/phpstan-packages
- dev-renovate/actions-cache-4.x
- dev-renovate/major-phpstan-packages
- dev-dependabot/composer/symfony/process-6.4.14
- dev-renovate/major-test-packages
- dev-renovate/lock-file-maintenance
This package is auto-updated.
Last update: 2024-12-21 07:47:19 UTC
README
The term Chimera (/kɪˈmɪərə/ or /kaɪˈmɪərə/) has come to describe any mythical or fictional animal with parts taken from various animals, or to describe anything composed of very disparate parts, or perceived as wildly imaginative, implausible, or dazzling.
There are many many amazing libraries in the PHP community and with the creation and adoption of the PSRs we don't necessarily need to rely on full stack frameworks to create a complex and well designed software. Choosing which components to use and plugging them together can sometimes be a little challenging.
The goal of this set of packages is to make it easier to do that (without compromising the quality), allowing you to focus on the behaviour of your software.
This project provides an implementation for chimera/foundation
that
uses league/tactician
as service bus.
Installation
Package is available on Packagist, you can install it using Composer.
composer require chimera/bus-tactician
Usage
The only thing you need to do in order to plug tactician into chimera is to create an instance of the command bus as you usually do and pass it to the decorator:
<?php use Chimera\ServiceBus\Tactician\ServiceBus; use League\Tactician\CommandBus; $middlewareList = []; // list of middleware to be used to process commands $commandBus = new ServiceBus(new CommandBus($middlewareList));
Usually the write and read concerns have different needs, which means that the list of middleware will definitely vary, so it's highly suggested that you create two service buses: a query bus and a command bus:
<?php use Chimera\ServiceBus\Tactician\ServiceBus; use League\Tactician\CommandBus; $writeMiddleware = []; // list of middleware to be used to process commands $commandBus = new ServiceBus(new CommandBus($writeMiddleware)); $readMiddleware = []; // list of middleware to be used to process queries $queryBus = new ServiceBus(new CommandBus($readMiddleware));
Domain to read model conversion
It's a good practice to completely isolate your domain model from your read model (also known as response model). This is important to prevent UI components (e.g.: request handlers - HTTP controllers - or CLI commands) from manipulating your aggregate roots and entities.
We provide the ReadModelConversionMiddleware
to handle such thing, and it should
be added to your query bus (since nothing is really returned from command buses):
<?php use Chimera\ServiceBus\ReadModelConverter\Callback; use Chimera\ServiceBus\Tactician\ReadModelConversionMiddleware; use Chimera\ServiceBus\Tactician\ServiceBus; use League\Tactician\CommandBus; // list of middleware to be used to process queries $readMiddleware = [ // many different middleware according to your needs new ReadModelConversionMiddleware(new Callback()), // you can use different strategies if needed // the handler locator middleware provided by tactician ]; $queryBus = new ServiceBus(new CommandBus($readMiddleware));
License
MIT, see LICENSE.