\Anax\RouteRouterInjectable

A container for routes.

Summary

Methods
Properties
Constants
setApp()
handle()
handleInternal()
load()
any()
add()
always()
all()
get()
post()
put()
delete()
addInternal()
getLastRoute()
getAll()
getInternal()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
$app
$routes
$internalRoutes
$lastRoute
N/A

Properties

$app

$app : 

Properties

Type

$routes

$routes : array

Type

array — all the routes.

$internalRoutes

$internalRoutes : 

Type

$lastRoute

$lastRoute : 

Type

Methods

setApp()

setApp(object  $app) : $this

Inject the $app into this class.

Parameters

object $app

containing framework resources.

Returns

$this —

for chaining.

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\NotFoundException

load()

load(string  $file) : self

Load routes from a config file, the file should return an array with routes.

Parameters

string $file

to load routes from.

Returns

self

any()

any(null|string|array  $method, null|string|array  $rule, null|string|callable  $action) : \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.

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.