PHP code example of middlewares / base-path-router

1. Go to this page and download the library: Download middlewares/base-path-router 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/ */

    

middlewares / base-path-router example snippets


$dispatcher = new Dispatcher([
    new Middlewares\BasePathRouter([
        '/admin' => $admin,
        '/admin/login' => $adminLogin,
        '/blog' => $blog,
    ]),
    new Middlewares\RequestHandler()
]);

$response = $dispatcher->dispatch(new ServerRequest());

$router = new Middlewares\BasePathRouter([
    '/foo' => $routerFoo,
    '/bar' => $routerBar,
    '/foo/bar' => $routerFooBar,
]);

$responseFactory = new MyOwnResponseFactory();

$router = new Middlewares\BasePathRouter($paths, $responseFactory);

$router = (new Middlewares\BasePathRouter([
        '/prefix1' => $middleware1,
    ]))->stripPrefix(false);

$dispatcher = new Dispatcher([
    //Save the route handler in an attribute called "route"
    (new Middlewares\BasePathRouter($paths))->attribute('route'),

    //Execute the route handler
    (new Middlewares\RequestHandler())->attribute('route')
]);