Binds icanboogie/message-bus to ICanBoogie

v5.0.0 2021-06-01 09:16 UTC

This package is auto-updated.

Last update: 2024-06-22 20:39:35 UTC



Packagist Build Status Code Quality Code Coverage Downloads

The icanboogie/bind-message-bus package binds icanboogie/message-bus to ICanBoogie.


use ICanBoogie\MessageBus\SimpleDispatcher;

/* @var \ICanBoogie\Application $app */

$bus = new SimpleDispatcher($app->message_handler_provider);
# or
$bus = $app->message_bus;


Application bindings

The following getters are added to the Application class:

  • message_bus: A Dispatcher instance created with $app->message_handler_provider and $app->message_pusher.
  • message_handler_provider: A HandlerProvider instance configured with the message-bus-handlers config.

/* @var \ICanBoogie\Application $app */


Controller bindings

The following method is added to the Controller class:

  • mixed dispatch_message($message): Dispatch a message using $this->app->command_bus.

Use the ControllerBindings trait with your controller to type hint the bindings.


use ICanBoogie\Routing\Controller;

class ProductController extends Controller
    use Controller\ActionTrait;
    use \ICanBoogie\Binding\MessageBus\ControllerBindings;

    protected function action_create()
        $message = new CreateProduct($this->request['payload']);
        $result = $this->dispatch_message($message);

        return $this->respond($result);


The message-bus config is used to configure the message bus. Message handlers are defined with an array of key/pair values with key MessageBusConfig::HANDLERS, where key is a message class and value its handler (a callable).

The following example demonstrates how to match messages with handler references. The icanboogie/service package provides the ref() method used to define the references:


namespace App\Application\Message;

use function ICanBoogie\Service\ref;
use ICanBoogie\Binding\MessageBus\MessageBusConfig;

return [

    MessageBusConfig::HANDLERS => [

        CreateArticle::class => ref('handler.article.create'),
        DeleteArticle::class => ref('handler.article.delete'),




The package requires PHP 7.2 or later.


composer require icanboogie/bind-message-bus


The package is documented as part of the ICanBoogie framework documentation. You can generate the documentation for the package and its dependencies with the make doc command. The documentation is generated in the build/docs directory. ApiGen is required. The directory can later be cleaned with the make clean command.


Run make test-container to create and log into the test container, then run make test to run the test suite. Alternatively, run make test-coverage to run the test suite with test coverage. Open build/coverage/index.html to see the breakdown of the code coverage.


icanboogie/bind-message-bus is released under the New BSD License.