PHP code example of racoon / router

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

    

racoon / router example snippets


$router->addRouteFile('/path/to/some_routes.php');

// Tells the router you are done adding routes so as it can process them.
$router->init();

$router
    ->addRouteFile('/path/to/some_routes.php')
    ->addRouteFile('/path/to/more_routes.php')
    ->addRouteFile('/path/to/even_more_routes.php');

// Tells the router you are done adding routes so as it can process them.
$router->init();

$router->addRouteCallable(function($r) {
    // Define your routes here as if they were in another file.
    // $r->addRoute(), $r->addGroup(), etc are all available.
});

$httpRequestMethod = ['GET', 'POST'];
$requestUri = '/users/list';
$handlerString = '\\MyApp\\Users@list';
$r->addRoute($httpRequestMethod, $requestUri, $handlerString);

$r->addRoute(['GET', 'POST'], '/users/list', '\\MyApp\\Users@list');
$r->addRoute(['GET', 'POST'], '/users/get', '\\MyApp\\Users@get');
$r->addRoute(['GET', 'POST'], '/users/update', '\\MyApp\\Users@update');
$r->addRoute(['GET', 'POST'], '/users/delete', '\\MyApp\\Users@delete');

$r->addGroup('/users', function () {
    $r->addRoute(['GET', 'POST'], '/list', '\\MyApp\\Users@list');
    $r->addRoute(['GET', 'POST'], '/get', '\\MyApp\\Users@get');
    $r->addRoute(['GET', 'POST'], '/update', '\\MyApp\\Users@update');
    $r->addRoute(['GET', 'POST'], '/delete', '\\MyApp\\Users@delete');
});

$r->addRoute(['GET', 'POST'], '/some/long/url/do-something', '\\MyApp\\Users@list');

$r->addGroup('/some', function ($r) {
    $r->addGroup('/long', function ($r) {
        $r->addGroup('/url', function ($r) {
            $r->addRoute(['GET', 'POST'], '/do-something', '\\MyApp\\Users@list');
        });
    });
});

'/users/list'
'/users/get/{userId}'
'/users/get/{userId:\d+}'