PHP code example of ashleydawson / command-bus
1. Go to this page and download the library: Download ashleydawson/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/ */
ashleydawson / command-bus example snippets
namespace Acme\Command;
class MyCommand
{
public $something;
}
namespace Acme\Command;
class MyCommandHandler
{
public function __invoke(MyCommand $command)
{
// Do something with the command here
return 'Something useful';
}
}
shleyDawson\CommandBus\CommandBus;
use Acme\Command\MyCommand;
use Acme\Command\MyCommandHandler;
// Instantiate a command bus
$commandBus = new CommandBus();
// Add a handler to the bus
$commandBus->addHandler(new MyCommandHandler());
// Execute a command, "Something useful" will be echoed
echo $commandBus->execute(new MyCommand());