MultilangRouter
extends Router
in package
A Multilingual Router
Table of Contents
Properties
- $notFoundCallback : array<string|int, mixed>
- $allowedLanguages : array<string|int, mixed>
- List of allowed languages
- $defaultLanguage : string
- The Default langauge
Methods
- __construct() : mixed
- A Multilingual Router
- 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
Properties
$notFoundCallback
protected
array<string|int, mixed>
$notFoundCallback
= []
[object|callable] The function to be executed when no route has been matched
$allowedLanguages
List of allowed languages
private
array<string|int, mixed>
$allowedLanguages
= array()
$defaultLanguage
The Default langauge
private
string
$defaultLanguage
Methods
__construct()
A Multilingual Router
public
__construct(array<string|int, mixed> $allowedLanguages, string $defaultLanguage) : mixed
Parameters
- $allowedLanguages : array<string|int, mixed>
- $defaultLanguage : string
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