php-ddd/command

命令查询责任分离模式(CQRS)的命令部分

v1.0.2 2015-01-01 11:55 UTC

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 只能处理一个 CommandInterface
  • CommandBus 只会分发一些 CommandInterface(以及更多)
  • CommandHandlerLocator 负责注册 CommandCommandHandler 之间的关联

它允许我们强制执行一些其他约定,例如需要匹配所处理 Command 名称的 CommandHandler 类名称。例如:AddItemToChartCommand 将由一个 AddItemToChartCommandHandler 对象处理。