smoothphp / commandbus
Smooth Php 命令总线
v5.0.0
2016-10-04 07:58 UTC
Requires
- php: >=5.5.0
- ramsey/uuid: ~2.8
- smoothphp/contracts: 1.0.*
Requires (Dev)
- phpunit/phpunit: 4.*
README
命令总线存在于应用程序域内执行写或失败的命令。
命令总线由4个组件组成。
- 命令
包含执行命令的意图和数据的DTO。 - 命令转换器
接受命令,并将其转换为命令处理类名称。 - 处理器解析器
解析(生成)执行给定命令的对象 - 中间件
位于CommandBus::execute()
和执行命令之间。类似于HTTP中间件。
示例
<?php
// Define as many middlewares as you like,
// the given one uses the simple translator and resolver to
// generate the command handler
$middleware = [
new SmoothPhp\CommandBus\CommandHandlerMiddleware(
new SmoothPhp\CommandBus\SimpleCommandTranslator,
new SmoothPhp\CommandBus\SimpleCommandHandlerResolver
)
];
// Create the bus with the middle ware
$bus = new SmoothPhp\CommandBus\CommandBus($middleware);
// Create the command
$command = new SignUpToNewsletter($memberId, $newsletterId);
// Send to command bus
$bus->execute($command);