Constants

DEVELOPMENT

DEVELOPMENT

PRODUCTION

PRODUCTION

Properties

$di

$di : \Anax\DI\Anax\DI\DIInterface

Type

\Anax\DI\Anax\DI\DIInterface — the DI service container.

$config

$config : array<mixed,>

Type

array<mixed,> — store the configuration in this array.

$routes

$routes : array

Type

array — all the routes.

$internalRoutes

$internalRoutes : 

Type

$lastRoute

$lastRoute : 

Type

Methods

setDI()

setDI(\Anax\DI\Anax\DI\DIInterface  $di) : self

Set the service container to use

Parameters

\Anax\DI\Anax\DI\DIInterface $di

a service container

Returns

self

configure()

configure(array|string  $what) : self

Load and apply configurations.

Parameters

array|string $what

is an array with key/value config options or a file to be included which returns such an array.

Returns

self

getConfig()

getConfig(string  $key, string  $default = null) : mixed

Helper function for reading values from the configuration and appy default values where configuration item is missing.

Parameters

string $key

matching a key in the config array.

string $default

value returned when config item is not found.

Returns

mixed —

or null if key does not exists.

handle()

handle(string  $path, string  $method = null) : mixed

Handle the routes and match them towards the request, dispatch them when a match is made. Each route handler may throw exceptions that may redirect to an internal route for error handling.

Several routes can match and if the routehandler does not break execution flow, the route matching will carry on. Only the last routehandler will get its return value returned further.

Parameters

string $path

the path to find a matching handler for.

string $method

the request method to match.

Returns

mixed —

content returned from route.

handleInternal()

handleInternal(string  $rule) : void

Handle an internal route, the internal routes are not exposed to the end user.

Parameters

string $rule

for this route.

Throws

\Anax\Route\Exception\NotFoundException

load()

load(array  $route) : self

Load routes from a config file, the file should return an array with details of the routes. These details are used to create the routes.

Parameters

array $route

details on the route.

Throws

\Anax\Route\Exception\ConfigurationException

Returns

self

any()

any(null|string|array  $method, null|string|array  $rule, null|string|callable  $action, null|string  $info = null) : \Anax\Route\class|array

Add a route with a request method, a path rule to match and an action as the callback. Adding several path rules (array) results in several routes being created.

Parameters

null|string|array $method

as a valid request method.

null|string|array $rule

path rule for this route.

null|string|callable $action

to implement a handler for the route.

null|string $info

about the route.

Returns

\Anax\Route\class|array —

as new route(s), class if one added, else array.

add()

add(null|string|array  $rule, null|string|callable  $action = null) : \Anax\Route\class|array

Add a route to the router by rule(s) and a callback.

Parameters

null|string|array $rule

for this route.

null|string|callable $action

a callback handler for the route.

Returns

\Anax\Route\class|array —

as new route(s), class if one added, else array.

always()

always(string|callable  $action) : \Anax\Route\class

Add a default route which will be applied for any path.

Parameters

string|callable $action

a callback handler for the route.

Returns

\Anax\Route\class —

as new route.

all()

all(null|string|array  $method, null|string|callable  $action) : \Anax\Route\class|array

Add a default route which will be applied for any path, if the choosen request method is matching.

Parameters

null|string|array $method

as request methods

null|string|callable $action

a callback handler for the route.

Returns

\Anax\Route\class|array —

as new route(s), class if one added, else array.

get()

get(  $rule, null|string|callable  $action) : \Anax\Route\class|array

Shortcut to add a GET route.

Parameters

$rule
null|string|callable $action

a callback handler for the route.

Returns

\Anax\Route\class|array —

as new route(s), class if one added, else array.

post()

post(  $rule, null|string|callable  $action) : \Anax\Route\class|array

Shortcut to add a POST route.

Parameters

$rule
null|string|callable $action

a callback handler for the route.

Returns

\Anax\Route\class|array —

as new route(s), class if one added, else array.

put()

put(  $rule, null|string|callable  $action) : \Anax\Route\class|array

Shortcut to add a PUT route.

Parameters

$rule
null|string|callable $action

a callback handler for the route.

Returns

\Anax\Route\class|array —

as new route(s), class if one added, else array.

delete()

delete(  $rule, null|string|callable  $action) : \Anax\Route\class|array

Shortcut to add a DELETE route.

Parameters

$rule
null|string|callable $action

a callback handler for the route.

Returns

\Anax\Route\class|array —

as new route(s), class if one added, else array.

addInternal()

addInternal(string  $rule, null|string|callable  $action) : \Anax\Route\class|array

Add an internal route to the router, this route is not exposed to the browser and the end user.

Parameters

string $rule

for this route

null|string|callable $action

a callback handler for the route.

Returns

\Anax\Route\class|array —

as new route(s), class if one added, else array.

getLastRoute()

getLastRoute() : mixed

Get the route for the last route that was handled.

Returns

mixed

getAll()

getAll() : array

Get all routes.

Returns

array —

with all routes.

getInternal()

getInternal() : array

Get all internal routes.

Returns

array —

with internal routes.