2017 © Pedro Peláez
 

library minibus

Minibus is a simple implementation of a workflow bus.

image

knplabs/minibus

Minibus is a simple implementation of a workflow bus.

  • Friday, August 21, 2015
  • by davidjegat
  • Repository
  • 0 Watchers
  • 3 Stars
  • 79 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 2 Forks
  • 1 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Minibus Build Status Scrutinizer Code Quality ![Gitter](https://badges.gitter.im/Join Chat.svg)

minibus , (*1)

Hey welcome to you traveler! You are looking for a way of traveling through your software easily? Do not search anymore, you've just find the place!, (*2)

Ladies and gentleman, let me present you the famous, the incredible, the revolutionary PHP Minibus !, (*3)

The goal

If you are like me, you are probably coding software solutions. In many software architectures the story starts with an Entry point (cf: a controller in an MVC application). But if you think about this Entry Point you probably agree with me that it's not only one point but, in many cases, a mix of many components that interact between them!, (*4)

In order to avoid what I call SMFB architecture (understand: Super Mega Fuc**** Brain, as the Controller) I present you Minibus!, (*5)

The principle is simple. In order to handle an application Entry Point we need three components:, (*6)

  • A Minibus, which contains various passengers (understand data).
  • Some Stations, that can handle a minibus at some point (replace the controller).
  • A bus Line that contains Stations and can guide a Minibus.
  • Optionaly a Terminus that can handle how to display the passengers.

Cool! Let's rock!

A basic example would be somethong like this:, (*7)

use Knp\Minibus\Station;
use Knp\Minibus\Minibus;

class CrazyStation implements Station
{
    public function handle(Minibus $minibus, array $configuration = [])
    {
        // You can add passenger
        $minibus->addPassenger('Sheldon', ['name' => 'Cooper', 'from' => 'The Big Bang Theory']);

        // Ensure a passenger existence
        if (!$minibus->hasPassenger('Sheldon')) {
            throw new \Exception('Wow something is going wrong :/');
        }

        // Retrieve a passenger
        $from = $minibus->getPassenger('Sheldon')['from'];

        // Or add as many passengers you want
        $minibus->setPassengers([
            'George' => 'Abitbol',
        ]);
    }
}

Once you have some stations, you need to create a Minibus and a Line:, (*8)

// test.php

use Knp\Minibus\Minibus\Minibus;
use Knp\Minibus\Line\Line;

$minibus = new Minibus;
$line    = new Line;

// add the station in the line
$line->addStation(new CrazyStation);

// finally lead te minibus thrue all the registered stations
$line->lead($minibus); // return the minibus

echo $minibus->getPassenger('George'); // print "Abitbol" :)

Go further

This is some other documentations that explain everything in details:, (*9)

The Versions