承接 proyectotau/command-bus 相关项目开发

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

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

proyectotau/command-bus

Composer 安装命令:

composer require proyectotau/command-bus

包简介

Minimalist implementation of CommandBus pattern for test purpose only

README 文档

README

Minimalist implementation of CommandBus pattern for test purpose only

According to (it remembers remotelly to)

https://tactician.thephpleague.com/

Install

Insert official repository in your composer.json

    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/proyectotau/command-bus.git"
        }
    ],

Require it by composer

   composer -vvv require proyectotau/command-bus:dev-master

Usage

Create a CommandHandler class

class CommandHandler {
	
	function handler($cmd){
		// run your task here
		// you can get public var from cmd if it is an object
	}
}

Make a CommandBus class

	$cmdbus = new CommandBus();

And bind command to that command handler

	$cmdbus->bind('MyCommand', $handler);

Command can be an object with parameters

	$cmdobj = new CommandObject(true, 1, []);
	$cmdbus->bind($cmdobj, $handler);

Finally, dispatch command

	$cmdbus->dispatch('MyCommand');

or

	$cmdbus->dispatch($cmdobj);

As a result, handler method will be invoke receiving command as an argument. If it is an object, you could get constructor's params. Let command be an object like this:

class CommandObject {
	public $param1;
	public $param2;
	public $param3;
	
	function __constructor($param1, $param2, $param3) {
		$this->param1 = $param1;
		$this->param2 = $param2;
		$this->param3 = $param3;
	}
}

You can pick up them

function handler($cmd){
		$this->param1 = $cmd->param1;
		$this->param2 = $cmd->param2;
		$this->param3 = $cmd->param3;
	}

Tests

You can run tests like this

vendor/bin/phpunit --color --testdox tests/CommandBusTest.php

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: GPLv2
  • 更新时间: 2022-03-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固