php-ddd / command
命令查询责任分离模式(CQRS)的命令部分
v1.0.2
2015-01-01 11:55 UTC
Requires
- php: >=5.3.3
- php-ddd/domain-event: ~1.0
Requires (Dev)
- fabpot/php-cs-fixer: dev-master
- phpunit/phpunit: 4.0.*
This package is not auto-updated.
Last update: 2024-09-14 16:39:48 UTC
README
此库提供了一些有用的工具,用于创建简单的命令系统。
工作原理
// configuration $handler = new AddItemToChartCommandHandler(); $locator = new CommandHandlerLocator(); $locator->register('AddItemToChartCommand', $handler); $bus = new SequentialCommandBus($locator); // usage $command = new AddItemToChartCommand($item, $chart); $bus->dispatch($command); // internally, the bus will call the corresponding handler.
约定
我们希望遵循单一职责原则。因此
CommandHandler只能处理一个CommandInterfaceCommandBus只会分发一些CommandInterface(以及更多)CommandHandlerLocator负责注册Command和CommandHandler之间的关联
它允许我们强制执行一些其他约定,例如需要匹配所处理 Command 名称的 CommandHandler 类名称。例如:AddItemToChartCommand 将由一个 AddItemToChartCommandHandler 对象处理。