PHP code example of lizzyman04 / file-router

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

    

lizzyman04 / file-router example snippets


use FileRouter\FileRouter;

$router = new FileRouter(__DIR__ . '/routes');

$match = $router->match($_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI']);

if ($match === null) {
    http_response_code(404);
} elseif ($match->isMethodNotAllowed()) {
    http_response_code(405);
    header('Allow: ' . implode(', ', $match->allowedMethods));
} else {
    // $match->file   — the route file to 

$match = $router->match(
    $request->getMethod(),
    $request->getUri()->getPath()
);

$router = new FileRouter(__DIR__ . '/routes', [
    // Where compiled routes are cached. Omit for no caching (compile per request).
    'cacheDir' => __DIR__ . '/var/cache',
    'cache'    => true,

    // How route files declare their HTTP methods. Default: Flow syntax.
    'methodExtractor' => new \FileRouter\Extractor\FlowMethodExtractor(),
]);

$router->clearCache(); // invalidate the compiled table