PHP code example of ellipse / dispatcher-controller

1. Go to this page and download the library: Download ellipse/dispatcher-controller 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/ */

    

ellipse / dispatcher-controller example snippets




namespace App;

use SomePsr11Container;

use Ellipse\DispatcherFactory;
use Ellipse\Dispatcher\ControllerResolver;

// Get some Psr-11 container.
$container = new SomePsr11Container;

// Decorate a DispatcherFactoryInterface implementation with a ControllerResolver.
$factory = new ControllerResolver($container, new DispatcherFactory);



namespace App;

use SomePsr11Container;

use Ellipse\DispatcherFactory;
use Ellipse\Dispatcher\ControllerResolver;

use App\Controllers\SomeController;

// Get some Psr-11 container.
$container = new SomePsr11Container;

// Decorate a DispatcherFactoryInterface implementation with a ControllerResolver.
$factory = new ControllerResolver($container, new DispatcherFactory);

// Dispatchers using controller definitions as Psr-15 request handler can now be created.
$dispatcher1 = $factory([SomeController::class, '@index'], [new SomeMiddleware]);
$dispatcher2 = $factory([SomeController::class, '@show', ['some_id']], [new SomeMiddleware]);
$dispatcher3 = $factory([SomeController::class, '@store'], [new SomeMiddleware]);