PHP code example of isholao / router

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

    

isholao / router example snippets




\Isholao\Router\RouteCollection();
$c->get('/','get_all_users_responder');
$c->mapMany('GET|POST','/login','login_responder','login');
$c->disptach('GET','/login'); //return Route instance or null

$c = \Isholao\Router\RouteCollection();
$c->mapOne('GET', '/login', 'defined_responder');
$c->mapOne('GET', '/{lang=(?:en|de)}/login', 'defined_responder');
or
$c->mapMany('GET|POST', '/login, 'defined_responder');

$c = \Isholao\Router\RouteCollection();
$c->mapOne('GET', '/something/{hash=[a-zA-Z]+}?', 'defined_responder');
or
$c->mapMany('GET|POST', '/login, 'defined_responder');

$c = \Isholao\Router\RouteCollection();
$c->mapOne('GET', '/something/{hash=[a-zA-Z]+}', 'defined_responder')->setParam('hash','asd8asdasd9');
or
$c->delete('/something/{hash=[a-zA-Z]+}', 'defined_responder')->setParam('hash','asd8asdasd9');

$c = \Isholao\Router\RouteCollection();
$c->groupRoutes('/admin', function (\Isholao\Router\RouteCollectionInterface $r) {
    $r->mapOne('GET', '/do-something', 'handler'); // this becomes `/admin/do-something`
    $r->post('/do-something-else', function(){}); //  // this becomes `/admin/do-another-thing`
});

$c = \Isholao\Router\RouteCollection();
$c->groupRoutes('/admin', function (\Isholao\Router\RouteCollectionInterface $r) {
    $r->mapOne('GET', '/do-something', 'handler'); // this becomes `/admin/do-something`
    $r->post('/do-something-else', function(){}); //  // this becomes `/admin/do-another-thing`
});

$c->dispatch('GET','/admin/do-something'); // return a \Isholao\Router\Route instance or null