承接 tomwright/commander 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

tomwright/commander

Composer 安装命令:

composer require tomwright/commander

包简介

A simple command bus.

README 文档

README

Build Status Latest Stable Version Total Downloads Monthly Downloads Daily Downloads License

Usage

You need a Command and a CommandHandler.

Let's say we have a command class stored in app/commanding/command/RegisterUserCommand.php.

namespace App\Commanding\Command;

class RegisterUserCommand extends \TomWright\Commander\Command\Command
{
	protected $username;
    protected $password;
    
    public function setUsername($username)
    {
    	$this->username = $username;
    }
    
    public function getUsername()
    {
    	return $this->username;
    }
    
    public function setPassword($password)
    {
        $this->password = $password;
    }
    
    public function getPassword()
    {
        return $this->password;
    }
}

Let's also assume we have a command handler class stored in app/commanding/handler/RegisterUserHandler.php.

namespace App\Commanding\Handler;

class RegisterUserHandler implements \TomWright\Commander\Handler\HandlerInterface
{   
    public function handle(\TomWright\Commander\Command\CommandInterface $command)
    {
    	echo "Registering user \"{$command->getUsername()}\" with password \"{$command->getPassword()}\".";
    }
}

Now we need to add a Command Handler namespace so as the CommandBus knows where to look for the handlers.

$bus = \TomWright\Commander\CommandBus::getInstance();
$bus->addHandlerNamespace('\\App\\Commanding\\Handler');

Now whenever we want to register a new user, all we have to do is the following:

$bus = \TomWright\Commander\CommandBus::getInstance();
$command = new \App\Commanding\Command\RegisterUserCommand();
$command->setUsername('Some user');
$command->setPassword('Somepassword123');
$bus->handle($command);

Remember - a Command is an action and not a notification. If you are looking for a notification/event handler see TomWright/Eventing.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2016-03-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固