PHP code example of prooph / service-bus
1. Go to this page and download the library: Download prooph/service-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/ */
prooph / service-bus example snippets
use Prooph\ServiceBus\CommandBus;
use Prooph\ServiceBus\Example\Command\EchoText;
use Prooph\ServiceBus\Plugin\Router\CommandRouter;
$commandBus = new CommandBus();
$router = new CommandRouter();
//Register a callback as CommandHandler for the EchoText command
$router->route('Prooph\ServiceBus\Example\Command\EchoText')
->to(function (EchoText $aCommand): void {
echo $aCommand->getText();
});
//Expand command bus with the router plugin
$router->attachToMessageBus($commandBus);
//We create a new Command
$echoText = new EchoText('It works');
//... and dispatch it
$commandBus->dispatch($echoText);
//Output should be: It works
console
$ php ./vendor/bin/bookdown docs/bookdown.json
$ php -S 0.0.0.0:8080 -t docs/html/