MinibusBundle
![Gitter](https://badges.gitter.im/Join Chat.svg)
Yolo Yolo ^.^. This is an integration of Minibus for Symfony2 applications.
Minibus is a standalone PHP 5.4 library which allows you to decouple your application responsabilities and actions into plural stations. The main goal is to create meaningful controllers and limit their responsabilities. For example with Minibus, your application entry points have nothing to do with the view. Their responsability will only be to change and retrieve a given state.
Install the bundle:
$ php composer.phar require knplabs/knp-minibus-bundle
Update your AppKernel
:
// app/AppKernel.php
$bundles = [
// ...
new Knp\MinibusBundle\KnpMinibusBundle,
];
You were waiting for a demonstration, here it is!
In order to start working with Minibus you need to create your first MinibusBundle
:
namespace App;
use Knp\MinibusBundle\Bundle\MinibusBundle;
class AppBundle extends MinibusBundle
{
}
Now register it inside your AppKernel
:
// app/AppKernel.php
$bundles = [
// ...
new App\AppBundle,
];
Stations are like controllers, except that you can launch as many stations as you
want during one action and the station does not handle any kind of view.
In fact the only role of a station is to create/retrieve/update Minibus
passengers.
(understand data).
Station must be located under BundleNamespace\Station
and implements
Knp\Minibus\Station
. This is a station example:
namespace App\Station;
use Knp\Minibus\Station;
use Knp\Minibus\Minibus;
class UsernameStation implements Station
{
public function handle(Minibus $minibus, array $configuration = [])
{
$minibus->addPassenger('username', 'Sheldon Cooper');
}
}
MinibusBundle comes with a complete yaml routing syntax that allows you to easily create a line. Once you get some stations ready to be used you can load a minibus routing:
# app/config/routing.yml
app:
resource: @AppBundle/Resources/config/routing.yml
type: minibus
prefix: /
Here comes the routing:
app_some_action:
pattern: /some/action
method: GET
line:
app.username: ~
app.other: ~
app.magic: ~
terminus:
twig:
template: "App::some.html.twig"
passengers:
magic_man:
service: some_service_id
method: getMagicMan
That's pretty it. Give it a try!.
Of course if you want a complete documentation of this bundle you just have to follow the guide!