class Router (View source)

Properties

static protected array $routes

Route collection.

protected array $error_code

Define the functions related to a 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.

Methods

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

Router constructor

static Router
configure(string|null $magic_method = null, string $base_route = '', array $middlewares = [])

Configure route singleton instance

static Router|null
getInstance()

Get the instance of router

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

void
setPrefix(string $prefix)

Set prefix

prefix(string $prefix, callable $cb)

Add a prefix on the roads

void
route(array $definition)

Route mapper

middleware(array|string $middlewares)

Allows to associate a global middleware on a route

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.

array
getErrorCodes()

Get the error codes

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

Match route de tout type de method

array
getRoutes()

Get the route collection

string
getSpecialMethod()

Retrieve the define special method

bool
hasSpecialMethod()

Check user define the special method

void
setCurrentPath(string $path)

Set the current path

Details

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

Router constructor

Parameters

string|null $magic_method
string $base_route
array $middlewares

static Router configure(string|null $magic_method = null, string $base_route = '', array $middlewares = [])

Configure route singleton instance

Parameters

string|null $magic_method
string $base_route
array $middlewares

Return Value

Router

static Router|null getInstance()

Get the instance of router

Return Value

Router|null

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

void setPrefix(string $prefix)

Set prefix

Parameters

string $prefix

Return Value

void

Router prefix(string $prefix, callable $cb)

Add a prefix on the roads

Parameters

string $prefix
callable $cb

Return Value

Router

Exceptions

void route(array $definition)

Route mapper

Parameters

array $definition

Return Value

void

Exceptions

RouterException

Router middleware(array|string $middlewares)

Allows to associate a global middleware on a route

Parameters

array|string $middlewares

Return Value

Router

Route 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

Route

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

array getErrorCodes()

Get the error codes

Return Value

array

Route 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

Route

array getRoutes()

Get the route collection

Return Value

array

string getSpecialMethod()

Retrieve the define special method

Return Value

string

bool hasSpecialMethod()

Check user define the special method

Return Value

bool

void setCurrentPath(string $path)

Set the current path

Parameters

string $path

Return Value

void