$ composer require bauhaus/message-bus
<?php
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
Open an issue: https://github.com/bauhausphp/message-bus/issues Code: https://github.com/bauhausphp/contributor-tool