2017 © Pedro Peláez
 

library bus-tactician

Service bus adapter for league/tactician

image

chimera/bus-tactician

Service bus adapter for league/tactician

  • Thursday, May 24, 2018
  • by lcobucci
  • Repository
  • 1 Watchers
  • 1 Stars
  • 601 Installations
  • PHP
  • 1 Dependents
  • 1 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 467 % Grown

The README.md

Chimera - bus/tactician

![Total Downloads] ![Latest Stable Version] ![Unstable Version], (*1)

![Build Status] ![Code Coverage], (*2)

The term Chimera (_/kɪˈmɪərə/_ or /kaɪˈmɪərə/) has come to describe any mythical or fictional animal with parts taken from various animals, or to describe anything composed of very disparate parts, or perceived as wildly imaginative, implausible, or dazzling., (*3)

There are many many amazing libraries in the PHP community and with the creation and adoption of the PSRs we don't necessarily need to rely on full stack frameworks to create a complex and well designed software. Choosing which components to use and plugging them together can sometimes be a little challenging., (*4)

The goal of this set of packages is to make it easier to do that (without compromising the quality), allowing you to focus on the behaviour of your software., (*5)

This project provides an implementation for chimera/foundation that uses league/tactician as service bus., (*6)

Installation

Package is available on Packagist, you can install it using Composer., (*7)

composer require chimera/bus-tactician

Usage

The only thing you need to do in order to plug tactician into chimera is to create an instance of the command bus as you usually do and pass it to the decorator:, (*8)

<?php

use Chimera\ServiceBus\Tactician\ServiceBus;
use League\Tactician\CommandBus;

$middlewareList = []; // list of middleware to be used to process commands
$commandBus     = new ServiceBus(new CommandBus($middlewareList));

Usually the write and read concerns have different needs, which means that the list of middleware will definitely vary, so it's highly suggested that you create two service buses: a query bus and a command bus:, (*9)

<?php

use Chimera\ServiceBus\Tactician\ServiceBus;
use League\Tactician\CommandBus;

$writeMiddleware = []; // list of middleware to be used to process commands
$commandBus      = new ServiceBus(new CommandBus($writeMiddleware));

$readMiddleware = []; // list of middleware to be used to process queries
$queryBus       = new ServiceBus(new CommandBus($readMiddleware));

Domain to read model conversion

It's a good practice to completely isolate your domain model from your read model (also known as response model). This is important to prevent UI components (e.g.: request handlers - HTTP controllers - or CLI commands) from manipulating your aggregate roots and entities., (*10)

We provide the ReadModelConversionMiddleware to handle such thing, and it should be added to your query bus (since nothing is really returned from command buses):, (*11)

<?php

use Chimera\ServiceBus\ReadModelConverter\Callback;
use Chimera\ServiceBus\Tactician\ReadModelConversionMiddleware;
use Chimera\ServiceBus\Tactician\ServiceBus;
use League\Tactician\CommandBus;

// list of middleware to be used to process queries
$readMiddleware = [
    // many different middleware according to your needs
    new ReadModelConversionMiddleware(new Callback()), // you can use different strategies if needed
    // the handler locator middleware provided by tactician
];

$queryBus = new ServiceBus(new CommandBus($readMiddleware));

License

MIT, see LICENSE., (*12)

The Versions