chimera / bus-tactician
league/tactician的服务总线适配器
0.4.0
2021-02-24 21:13 UTC
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
This package is auto-updated.
Last update: 2024-09-20 16:48:45 UTC
README
术语Chimera(/kɪˈmɪərə/或/kaɪˈmɪərə/)用来描述任何由各种动物部分组成的神话或虚构动物,或者用来描述由非常不同的部分组成的事物,或者被认为是富有想象力、难以置信或令人眼花缭乱的。
PHP社区中有许多许多令人惊叹的库,随着PSRs的创建和采用,我们不一定需要依赖完整的堆栈框架来创建复杂且设计良好的软件。选择要使用的组件并将它们连接起来有时可能会有些挑战。
这些包集的目标是使这变得更容易(而不妥协质量),让您能够专注于您软件的行为。
本项目为chimera/foundation
提供了一个实现,该实现使用league/tactician
作为服务总线。
安装
该包可在Packagist上找到,您可以使用Composer进行安装。
composer require chimera/bus-tactician
用法
要将tactician连接到chimera,您只需创建一个命令总线实例,就像您通常做的那样,并将其传递给装饰器。
<?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));
通常,写入和读取关注点有不同的需求,这意味着中间件列表肯定会不同,因此强烈建议您创建两个服务总线:一个查询总线和一个命令总线。
<?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));
领域到读取模型转换
将领域模型与读取模型(也称为响应模型)完全隔离是一个好的做法。这很重要,可以防止UI组件(例如:请求处理器 - HTTP控制器 - 或CLI命令)操作您的聚合根和实体。
我们提供了ReadModelConversionMiddleware
来处理此类事情,并且应该将其添加到您的查询总线中(因为命令总线实际上没有返回任何内容)。
<?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));
许可证
MIT,请参阅LICENSE。