Router
in package
Class Router.
Table of Contents
Properties
- $notFoundCallback : array<string|int, mixed>
- $afterRoutes : array<string|int, mixed>
- $baseRoute : string
- $beforeRoutes : array<string|int, mixed>
- $namespace : string
- $requestedMethod : string
- $serverBasePath : string
Methods
- all() : mixed
- Shorthand for a route accessed using any method.
- before() : mixed
- Store a before middleware route and a handling function to be executed when accessed using one of the specified methods.
- delete() : mixed
- Shorthand for a route accessed using DELETE.
- get() : mixed
- Shorthand for a route accessed using GET.
- getBasePath() : string
- Return server base Path, and define it if isn't defined.
- getCurrentUri() : string
- Define the current relative URI.
- getNamespace() : string
- Get the given Namespace before.
- getRequestHeaders() : array<string|int, mixed>
- Get all request headers.
- getRequestMethod() : string
- Get the request method used, taking overrides into account.
- match() : mixed
- Store a route and a handling function to be executed when accessed using one of the specified methods.
- mount() : mixed
- Mounts a collection of callbacks onto a base route.
- options() : mixed
- Shorthand for a route accessed using OPTIONS.
- patch() : mixed
- Shorthand for a route accessed using PATCH.
- post() : mixed
- Shorthand for a route accessed using POST.
- put() : mixed
- Shorthand for a route accessed using PUT.
- run() : bool
- Execute the router: Loop all defined before middleware's and routes, and execute the handling function if a match was found.
- set404() : mixed
- Set the 404 handling function.
- setBasePath() : mixed
- Explicilty sets the server base path. To be used when your entry script path differs from your entry URLs.
- setNamespace() : mixed
- Set a Default Lookup Namespace for Callable methods.
- trigger404() : mixed
- Triggers 404 response
- handle() : int
- Handle a a set of routes: if a match is found, execute the relating handling function.
- invoke() : mixed
- patternMatches() : bool
- Replace all curly braces matches {} into word patterns (like Laravel) Checks if there is a routing match
Properties
$notFoundCallback
protected
array<string|int, mixed>
$notFoundCallback
= []
[object|callable] The function to be executed when no route has been matched
$afterRoutes
private
array<string|int, mixed>
$afterRoutes
= array()
The route patterns and their handling functions
$baseRoute
private
string
$baseRoute
= ''
Current base route, used for (sub)route mounting
$beforeRoutes
private
array<string|int, mixed>
$beforeRoutes
= array()
The before middleware route patterns and their handling functions
$namespace
private
string
$namespace
= ''
Default Controllers Namespace
$requestedMethod
private
string
$requestedMethod
= ''
The Request Method that needs to be handled
$serverBasePath
private
string
$serverBasePath
The Server Base Path for Router Execution
Methods
all()
Shorthand for a route accessed using any method.
public
all(string $pattern, object|callable $fn) : mixed
Parameters
- $pattern : string
-
A route pattern such as /about/system
- $fn : object|callable
-
The handling function to be executed
before()
Store a before middleware route and a handling function to be executed when accessed using one of the specified methods.
public
before(string $methods, string $pattern, object|callable $fn) : mixed
Parameters
- $methods : string
-
Allowed methods, | delimited
- $pattern : string
-
A route pattern such as /about/system
- $fn : object|callable
-
The handling function to be executed
delete()
Shorthand for a route accessed using DELETE.
public
delete(string $pattern, object|callable $fn) : mixed
Parameters
- $pattern : string
-
A route pattern such as /about/system
- $fn : object|callable
-
The handling function to be executed
get()
Shorthand for a route accessed using GET.
public
get(string $pattern, object|callable $fn) : mixed
Parameters
- $pattern : string
-
A route pattern such as /about/system
- $fn : object|callable
-
The handling function to be executed
getBasePath()
Return server base Path, and define it if isn't defined.
public
getBasePath() : string
Return values
stringgetCurrentUri()
Define the current relative URI.
public
getCurrentUri() : string
Return values
stringgetNamespace()
Get the given Namespace before.
public
getNamespace() : string
Return values
string —The given Namespace if exists
getRequestHeaders()
Get all request headers.
public
getRequestHeaders() : array<string|int, mixed>
Return values
array<string|int, mixed> —The request headers
getRequestMethod()
Get the request method used, taking overrides into account.
public
getRequestMethod() : string
Return values
string —The Request method to handle
match()
Store a route and a handling function to be executed when accessed using one of the specified methods.
public
match(string $methods, string $pattern, object|callable $fn) : mixed
Parameters
- $methods : string
-
Allowed methods, | delimited
- $pattern : string
-
A route pattern such as /about/system
- $fn : object|callable
-
The handling function to be executed
mount()
Mounts a collection of callbacks onto a base route.
public
mount(string $baseRoute, callable $fn) : mixed
Parameters
- $baseRoute : string
-
The route sub pattern to mount the callbacks on
- $fn : callable
-
The callback method
options()
Shorthand for a route accessed using OPTIONS.
public
options(string $pattern, object|callable $fn) : mixed
Parameters
- $pattern : string
-
A route pattern such as /about/system
- $fn : object|callable
-
The handling function to be executed
patch()
Shorthand for a route accessed using PATCH.
public
patch(string $pattern, object|callable $fn) : mixed
Parameters
- $pattern : string
-
A route pattern such as /about/system
- $fn : object|callable
-
The handling function to be executed
post()
Shorthand for a route accessed using POST.
public
post(string $pattern, object|callable $fn) : mixed
Parameters
- $pattern : string
-
A route pattern such as /about/system
- $fn : object|callable
-
The handling function to be executed
put()
Shorthand for a route accessed using PUT.
public
put(string $pattern, object|callable $fn) : mixed
Parameters
- $pattern : string
-
A route pattern such as /about/system
- $fn : object|callable
-
The handling function to be executed
run()
Execute the router: Loop all defined before middleware's and routes, and execute the handling function if a match was found.
public
run([object|callable $callback = null ]) : bool
Parameters
- $callback : object|callable = null
-
Function to be executed after a matching route was handled (= after router middleware)
Return values
boolset404()
Set the 404 handling function.
public
set404(object|callable|string $match_fn[, object|callable $fn = null ]) : mixed
Parameters
- $match_fn : object|callable|string
-
The function to be executed
- $fn : object|callable = null
-
The function to be executed
setBasePath()
Explicilty sets the server base path. To be used when your entry script path differs from your entry URLs.
public
setBasePath(mixed $serverBasePath) : mixed
Parameters
- $serverBasePath : mixed
Tags
setNamespace()
Set a Default Lookup Namespace for Callable methods.
public
setNamespace(string $namespace) : mixed
Parameters
- $namespace : string
-
A given namespace
trigger404()
Triggers 404 response
public
trigger404([mixed $match = null ]) : mixed
Parameters
- $match : mixed = null
handle()
Handle a a set of routes: if a match is found, execute the relating handling function.
private
handle(array<string|int, mixed> $routes[, bool $quitAfterRun = false ]) : int
Parameters
- $routes : array<string|int, mixed>
-
Collection of route patterns and their handling functions
- $quitAfterRun : bool = false
-
Does the handle function need to quit after one route was matched?
Return values
int —The number of routes handled
invoke()
private
invoke(mixed $fn[, mixed $params = array() ]) : mixed
Parameters
- $fn : mixed
- $params : mixed = array()
patternMatches()
Replace all curly braces matches {} into word patterns (like Laravel) Checks if there is a routing match
private
patternMatches(mixed $pattern, mixed $uri, mixed &$matches, mixed $flags) : bool
Parameters
- $pattern : mixed
- $uri : mixed
- $matches : mixed
- $flags : mixed
Return values
bool —-> is match yes/no