PHP code example of datapp / router

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

    

datapp / router example snippets




er = new Router(new Dispatcher());
// route without middlewares
$router->addRoute(Route::create('GET', '/^(help)$/', new Help($responseFactory, $streamFactory)));
// route with middlewares
$router->addRoute(Route::create('POST', '/^(login)$/', new Login($responseFactory, $streamFactory))
                ->withMiddleware(new SessionMiddleware(), new AuthMiddleware()));
// using variables (named groups) in regex
$router->addRoute(Route::create('GET', '/^(user)\/(?<id>[\d]+)$/', new UserShow($responseFactory, $streamFactory))
                ->withMiddleware(new SessionMiddleware(), new AuthMiddleware()));