nicwortel / command-pipeline
PHP 的命令管道
v0.4.0
2021-03-28 13:15 UTC
Requires
- php: ^7.4 || ^8.0
- beberlei/assert: ^2.1 || ^3.0
- doctrine/doctrine-bundle: ^1.11 || ^2.0
- doctrine/orm: ^2.6.3
- psr/log: ^1.1
- simple-bus/message-bus: ^6.0
- simple-bus/symfony-bridge: ^6.0
- symfony/config: ^4.0 || ^5.0
- symfony/dependency-injection: ^4.0 || ^5.0
- symfony/http-kernel: ^4.0 || ^5.0
- symfony/security-bundle: ^4.0 || ^5.0
- symfony/security-core: ^4.3 || ^5.0
- symfony/validator: ^4.4.4 || ^5.0.4
Requires (Dev)
- doctrine/annotations: ^1.7
- liip/rmt: ^1.6
- mockery/mockery: ^1.2.3
- nicwortel/coding-standard: ^2.0
- phpstan/phpstan: ^0.12.7
- phpunit/phpunit: ^9.4
- symfony/framework-bundle: ^4.0 || ^5.0
Conflicts
- doctrine/common: <2.12
- doctrine/doctrine-cache-bundle: <1.3.1
README
这是一个 PHP 的内存中命令管道实现。命令管道用于处理 CQRS 应用程序中的跨切面关注点,如命令验证、授权、日志记录等。
命令按线性过程处理。每个阶段的返回值传递给下一个阶段。一个阶段只能通过抛出异常来阻止下一个阶段的执行。
命令管道的概念是基于管道和过滤器模式的。
功能
- 命令验证
- 命令授权
- 将命令处理包装在 Doctrine 数据库事务中
- 将发出的领域事件发送到事件总线
安装
composer require nicwortel/command-pipeline
如果你使用的是 Symfony,请启用 CommandPipelineBundle
// config/bundles.php return [ // ... NicWortel\CommandPipeline\Bundle\CommandPipelineBundle::class => ['all' => true], ];
用法
从服务容器中获取 command_pipeline
服务或将 CommandPipeline
注入到你的应用程序代码中(推荐)
<?php declare(strict_types=1); use NicWortel\CommandPipeline\CommandPipeline; // ... class MyController { private CommandPipeline $commandPipeline; public function __construct(CommandPipeline $commandPipeline) { $this->commandPipeline = $commandPipeline; } public function saveAction(): Response { $command = new MyCommand(); $command->foo = 'bar'; $this->commandPipeline->process($command); // ... } }