PHP code example of knplabs / minibus

1. Go to this page and download the library: Download knplabs/minibus library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

knplabs / minibus example snippets


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',
        ]);
    }
}

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