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

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

Router constructor

void
setBaseRoute(string $base_route)

Set the base route

void
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

void
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|string|array $cb)

Add a OPTIONS route

code(int $code, callable|array|string $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 __construct(string $method, string|null $magic_method = null, string $base_route = '', array $middlewares = [])

Router constructor

Parameters

string $method
string|null $magic_method
string $base_route
array $middlewares

void setBaseRoute(string $base_route)

Set the base route

Parameters

string $base_route

Return Value

void

void setAutoCsrf(bool $auto_csrf)

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

Parameters

bool $auto_csrf

Return Value

void

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

void route(array $definition)

Route mapper

Parameters

array $definition

Return Value

void

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|string|array $cb)

Add a OPTIONS route

Parameters

string $path
callable|string|array $cb

Return Value

Route

Router code(int $code, callable|array|string $cb)

Launch a callback function for each HTTP error code.

When the define code match with response code.

Parameters

int $code
callable|array|string $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