tactics/command-bus-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tactics/command-bus-bundle

最新稳定版本:2.1.0

Composer 安装命令:

composer require tactics/command-bus-bundle

包简介

Handle Commands with CommandHandlers through a CommandBus

README 文档

README

Build Status Scrutinizer Code Quality

Say we have a command called RegisterUser.

<?php

use Pringles\DomainBundle\CommandBus\Command;

class RegisterUser implements Command
{
    public $firstname;
    public $lastname;
}

And we want to handle that command.

<?php

use Pringles\DomainBundle\CommandBus\CommandHandler;

class RegisterUserHandler implements CommandHandler
{
    private $personRepository;

    public function __construct(PersonRepository $personRepository)
    {
        $this->personRepository = $personRepository;
    }

    public function handle(RegisterUser $registerUser)
    {
        $person = Person::register($registerUser->firstname, $registerUser->lastname);
    }
}

We can setup the SimpleCommandBus, register the handler and handle the command.

<?php

use Pringles\DomainBundle\CommandBus\SimpleCommandBus;

function someController()
{
    $bus = new SimpleCommandBus(new ShortNameStrategy());
    $bus->registerHandler(new RegisterUserHandler($personRepository));

    $cmd = new RegisterUser;
    $cmd->firstname = 'Aaron';
    $cmd->lastname = 'Muylaert';

    $bus->handle($cmd);
}

SimpleCommandBus finds handlers based on their name. A command named Test requires a registered handler called TestHandler. If no handler is found, nothing happens.

Oh, one small rule, command handlers are not allowed to return values.

There is a command bus service called command_bus. You can register a handler by registering your handler as a service and tagging the service as command_handler. Using it looks like this:

<?php

$cmd = new Test;
$cmd->value = 'Foo';

$this->get('command_bus')->handle($cmd);

\m/

统计信息

  • 总下载量: 7.16k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 8
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-12-08