knplabs/minibus

Minibus is a simple implementation of a workflow bus.

0.0.1-beta 2014-11-24 21:12 UTC

This package is not auto-updated.

Last update: 2020-03-30 18:25:11 UTC


README

minibus

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!

Ladies and gentleman, let me present you the famous, the incredible, the revolutionary PHP Minibus !

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!

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

The principle is simple. In order to handle an application Entry Point we need three components:

  • 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:

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:

// 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: