PHP code example of robotusers / commander

1. Go to this page and download the library: Download robotusers/commander 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/ */

    

robotusers / commander example snippets


use Robotusers\Commander\CommandBusAwareInterface;
use Robotusers\Commander\CommandBusAwareTrait;

class OrdersController implements CommandBusAwareInterface
{
   use CommandBusAwareTrait;

   public function makeOrder()
   {
        ...
        $command = new MakeOrderCommand($data);
        $this->handleCommand($command);
        ...
   }

}

use League\Tactician\CommandBus;
use Robotusers\Commander\Adapter\TacticianAdapter;

$commandBus = new CommandBus($middleware);
$adapter = new TacticianAdapter($commandBus);

$controller->setCommandBus($adapter);

use Robotusers\Commander\Adapter\SimpleBusAdapter;
use SimpleBus\Message\Bus\Middleware\MessageBusSupportingMiddleware;

$commandBus = new MessageBusSupportingMiddleware();
$adapter = new SimpleBusAdapter($commandBus);

$controller->setCommandBus($adapter);

use Prooph\ServiceBus\CommandBus;
use Robotusers\Commander\Adapter\ServiceBusAdapter;

$commandBus = new CommandBus();
$adapter = new ServiceBusAdapter($commandBus);

$controller->setCommandBus($adapter);

class MyAdapter implements CommandBusInterface
{
    public function handle($command)
    {
        //handle a command
    }
}