class Router (View source)

Properties

protected array $error_code

Define the functions related to an http code executed if this code is up

protected array $middlewares

Define the global middleware

protected string $prefix

Define the routing prefix

protected string $special_method
protected array $current

Method Http current.

protected bool $auto_csrf

Define the auto csrf check status.

static protected array $routes

Route collection.

Methods

void
__construct($method, $magic_method = null, $base_route = '', array $middlewares = [])

Router constructor

setBaseRoute(string $base_route)

Set the base route

setAutoCsrf(bool $auto_csrf)

Set auto CSRF status Note: Disable only you run on test env

prefix(string $prefix, callable $cb)

Add a prefix on the roads

middleware(array $middlewares)

Allows to associate a global middleware on an route

route(array $definition)

Route mapper

any(string $path, callable|string|array $cb)

Add a route for

get(string $path, callable|string|array $cb)

Add a GET route

post(string $path, callable|string|array $cb)

Add a POST route

delete(string $path, callable|string|array $cb)

Add a DELETE route

put(string $path, callable|string|array $cb)

Add a PUT route

patch(string $path, callable|string|array $cb)

Add a PATCH route

options(string $path, callable $cb)

Add a OPTIONS route

code(int $code, callable $cb)

Launch a callback function for each HTTP error code.

match(array $methods, string $path, callable|string|array $cb)

Match route de tout type de method

string
getSpecialMethod()

Retrieve the define special method

bool
hasSpecialMethod()

Check user define the special method

array
getRoutes()

Get the route collection

Details

protected void __construct($method, $magic_method = null, $base_route = '', array $middlewares = [])

Router constructor

Parameters

$method
$magic_method
$base_route
array $middlewares

Return Value

void

setBaseRoute(string $base_route)

Set the base route

Parameters

string $base_route

setAutoCsrf(bool $auto_csrf)

Set auto CSRF status Note: Disable only you run on test env

Parameters

bool $auto_csrf

Router prefix(string $prefix, callable $cb)

Add a prefix on the roads

Parameters

string $prefix
callable $cb

Return Value

Router

Exceptions

Router middleware(array $middlewares)

Allows to associate a global middleware on an route

Parameters

array $middlewares

Return Value

Router

route(array $definition)

Route mapper

Parameters

array $definition

Exceptions

RouterException

Router any(string $path, callable|string|array $cb)

Add a route for

GET, POST, DELETE, PUT, OPTIONS, PATCH

Parameters

string $path
callable|string|array $cb

Return Value

Router

Exceptions

Route get(string $path, callable|string|array $cb)

Add a GET route

Parameters

string $path
callable|string|array $cb

Return Value

Route

Route post(string $path, callable|string|array $cb)

Add a POST route

Parameters

string $path
callable|string|array $cb

Return Value

Route

Route delete(string $path, callable|string|array $cb)

Add a DELETE route

Parameters

string $path
callable|string|array $cb

Return Value

Route

Route put(string $path, callable|string|array $cb)

Add a PUT route

Parameters

string $path
callable|string|array $cb

Return Value

Route

Route patch(string $path, callable|string|array $cb)

Add a PATCH route

Parameters

string $path
callable|string|array $cb

Return Value

Route

Route options(string $path, callable $cb)

Add a OPTIONS route

Parameters

string $path
callable $cb

Return Value

Route

Router code(int $code, callable $cb)

Launch a callback function for each HTTP error code.

When the define code match with response code.

Parameters

int $code
callable $cb

Return Value

Router

Router match(array $methods, string $path, callable|string|array $cb)

Match route de tout type de method

Parameters

array $methods
string $path
callable|string|array $cb

Return Value

Router

protected string getSpecialMethod()

Retrieve the define special method

Return Value

string

protected bool hasSpecialMethod()

Check user define the special method

Return Value

bool

array getRoutes()

Get the route collection

Return Value

array