PHP code example of proyectotau / command-bus

1. Go to this page and download the library: Download proyectotau/command-bus library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

proyectotau / command-bus example snippets


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

	$cmdbus = new CommandBus();

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

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

	$cmdbus->dispatch('MyCommand');

	$cmdbus->dispatch($cmdobj);

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

function handler($cmd){
		$this->param1 = $cmd->param1;
		$this->param2 = $cmd->param2;
		$this->param3 = $cmd->param3;
	}
sh
vendor/bin/phpunit --color --testdox tests/CommandBusTest.php