icanboogie/bind-message-bus

Binds icanboogie/message-bus to ICanBoogie

v0.1.0 2017-09-25 19:38 UTC

README

Packagist Build Status Code Quality Code Coverage Downloads

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

<?php

use ICanBoogie\MessageBus\SimpleDispatcher;

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

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

Bindings

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

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

$app->message_bus;
$app->message_handler_provider;

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.

<?php

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);
	}
}

Configuration

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:

<?php

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'),

	]

];

Requirements

The package requires PHP 5.6 or later.

Installation

The recommended way to install this package is through Composer:

$ composer require icanboogie/bind-message-bus

Cloning the repository

The package is available on GitHub, its repository can be cloned with the following command line:

$ git clone https://github.com/ICanBoogie/bind-message-bus.git

Documentation

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.

Testing

The test suite is ran with the make test command. PHPUnit and Composer need to be globally available to run the suite. The command installs dependencies as required. The make test-coverage command runs test suite and also creates an HTML coverage report in build/coverage. The directory can later be cleaned with the make clean command.

The package is continuously tested by Travis CI.

Build Status Code Coverage

License

icanboogie/bind-message-bus is licensed under the New BSD License - See the LICENSE file for details.