PHP code example of constanze-standard / routing

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

    

constanze-standard / routing example snippets


use ConstanzeStandard\Routing\RouteCollection;

$collection = new RouteCollection();

$collection->add('GET', '/foo/{bar:\d+}', 'serializable data', 'unserializable data');

use ConstanzeStandard\Routing\Matcher;
...

$matcher = new Matcher($collection);
$result = $matcher->match('GET', '/foo/12');

use ConstanzeStandard\Routing\RouteCollection;

$file = __DIR__ . '/cacheFile.php';
$collection = new RouteCollection($file);

$collection->add('GET', '/foo/{bar:\d+}', 'serializable data', 'unserializable data');
...

if (file_exists($file)) {
    $collection->loadCache();
} else {
    $collection->cache();
}