PHP code example of rosem / route

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

    

rosem / route example snippets

 php
$router = new Rosem\Route\Router();

$router->addRoute('GET', '/user/{id:\d+}', 'handle')
    ->addMiddleware('Auth', ['setType' => 'digest'])
    ->addMiddleware('CSRF');

$result = $router->dispatch('GET', '/user/123');

echo $result === [
    // HTTP status code
    0 => 200,
    // Handler
    1 => 'handle',
    // Middleware list
    2 => [
         0 => [
            0 => 'Auth',
            1 => [
                'setName' => 'digest',
            ]
         ],
         1 => [
            0 => 'CSRF',
            1 => []
         ],
    ],
    // Variables list
    3 => [
         'id' => '123',
    ],
];