DDD 的命令总线模式的 PHP 实现

1.0.0 2014-11-17 22:34 UTC

This package is auto-updated.

Last update: 2024-08-29 03:26:07 UTC


README

#Car

Car 是 DDD 的命令总线模式的 PHP 实现。

Build Status

##免责声明

这是一个非常基本且简单的实现。它需要成长 :)

##安装

composer require maximecolin/car

##目的

命令总线模式的目的是将您的领域代码隔离成原子、可测试和可重用的类,并通过专用服务执行它们。

##使用

命令是一种指令。它可以包含您所需的数据。属性可以在构造时设置,通过表单填写,由其他服务设置等。

class CreateArticleCommand implements CommandInterface
{
	public $title;
	public $content;
	
	public function __construct($title, $content)
	{
		$this->title   = $title;
		$this->content = $content;
	}
}

创建一个处理程序来处理您的命令。

class CreateCommandHandler implements CommandHandlerInterface
{
	public function handle(CommandInterface $command)
	{
		// Place here you domain code which create an article ...
	}
}
// Usually, have a service to get the bus
$bus = new CommandBus();
$bus->addResolver(new ClassNameResolver());

$command = new CreateArticleCommand('My article name', 'My article content');

$bus->execute($command);

##即将推出

事件源集成。