knplabs / minibus
Minibus is a simple implementation of a workflow bus.
Requires
- php: >=5.4
- symfony/config: ~2.4
- symfony/event-dispatcher: ~2.4
- symfony/options-resolver: ~2.4
Requires (Dev)
- bossa/phpspec2-expect: *
- docteurklein/funk-spec: dev-master
- jms/serializer: ~0.17@dev
- phpspec/nyan-formatters: *
- phpspec/phpspec: *
- symfony/http-foundation: ~2.4
- symfony/routing: ~2.4
- twig/twig: ~1.16@dev
Suggests
- jms/serializer: For the serializer terminus
- symfony/http-foundation: For using http terminus
- symfony/routing: For using route redirection terminus
- twig/twig: For the twig terminus
This package is not auto-updated.
Last update: 2024-12-17 16:35:24 UTC
README
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 containsStations
and can guide aMinibus
. - 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: