Tsugi

FileRouter
in package

Super Simple File Based Router

This router routes paths like .../install to .../install.php if the file exists.

$router = new Tsugi\Util\FileRouter();
$file = $router->fileCheck();
if ( $file ) {
    require_once($file);
    return;
}

This pattern uses GET parameters rather than REST parameters but a single route is all that is needed to route requests to a file. You should use one or the other but not both to keep things simple.

Table of Contents

Methods

cwd()  : mixed
Gives the current folder of the executing script
fileCheck()  : mixed
trimQuery()  : mixed

Methods

cwd()

Gives the current folder of the executing script

public static cwd() : mixed

["SCRIPT_NAME"]=> string(21) "/wa4e/tsugi/route.php"

returns "/wa4e/tsugi" (no trailing slash)

fileCheck()

public fileCheck([mixed $uri = null ][, mixed $defaultFile = 'index.php' ]) : mixed
Parameters
$uri : mixed = null
$defaultFile : mixed = 'index.php'

trimQuery()

public trimQuery(mixed $uri) : mixed
Parameters
$uri : mixed

        
On this page

Search results