PHP code example of bauhaus / message-bus
1. Go to this page and download the library: Download bauhaus/message-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/ */
bauhaus / message-bus example snippets
use Bauhaus\MessageBus;
use Bauhaus\MessageBusSettings;
class YourCommand {}
class YourCommandHandler
{
public function __invoke(CommandA $command): void {}
}
class YourQuery {}
class YourQueryResult {}
class YourQueryHandler
{
public function __invoke(YourQuery $query): YourQueryResult
{
return new YourQueryResult();
}
}
$messageBus = MessageBus::build(
MessageBusSettings::new()
->withPsrContainer(/* Pass here your favorite PSR container */)
->withHandlers(
YourCommandAHandler::class,
YourQueryHandler::class,
);
);
$result = $messageBus->dispatch(new YourCommand());
is_null($result); // true
$result = $messageBus->dispatch(new YourCommand());
$result instanceof YourQueryResult; // true