bauhaus/message-bus

Yet another message bus implementation

v0.0.0 2021-09-25 23:08 UTC

README

Build Status Coverage

Stable Version Downloads PHP Version License

Message Bus

Installing

$ composer require bauhaus/message-bus

Getting Started

<?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

Contributing

Open an issue: https://github.com/bauhausphp/message-bus/issues Code: https://github.com/bauhausphp/contributor-tool