Properties

$base

$base : string

Type

string — The class to resolve from the container when Router is called.

$paginateCurrentPage

$paginateCurrentPage : integer

Type

integer — The current page being requested for a paginated route.

$routers

$routers : array

Type

array — Collection of all instances of Routers we make.

$numberOfProcessedRoutes

$numberOfProcessedRoutes : integer

Type

integer — The number of routes that have been processed.

$routeMatch

$routeMatch : boolean

Type

boolean — Has a router matched a request?

$requestMethod

$requestMethod : string

Type

string — The request method the router servers ie : `get`,`post`,`put`,`delete`.

$uri

$uri : string

Type

string — URI path to match.

$action

$action : \Closure|string

Type

\Closure|string — Action to take if matched.

$variableRestrictions

$variableRestrictions : array

Type

array — The routers where restrictions.

$variables

$variables : array

Type

array — The extracted variables from the route uri based on the variableRestrictions.

$secureRoute

$secureRoute : boolean

Type

boolean — Is route HTTPS?

$isFilter

$isFilter : boolean

Type

boolean — Is this Router a Filter Router?

$filterBase

$filterBase : boolean

Type

boolean — When we a do a filter we store the base here

$filteredOn

$filteredOn : boolean

Type

boolean — When we a do a filter we store the filtered portion here

$useRouter

$useRouter : null|string|array|\Closure

Type

null|string|array|\Closure — Send a filtered route to Router file,an array of routes, or Closure.

$children

$children : null|array

Type

null|array — Children of a route.

$auth

$auth : null|string|array

Type

null|string|array — Store authentication requirements on route.

$allowURLParameters

$allowURLParameters : boolean

Type

boolean — Allow GET variables to be contained in the route.

$paginate

$paginate : boolean

Type

boolean — Is the route a paginated route?

Methods

factory()

factory() : \Disco\classes\Router

Get a new Router instance. This is the only method that should be used to access instances of this class.

Before the new Router instance is returned, any previously registered routers will be processed off the router stack.

Returns

\Disco\classes\Router

processLastCreatedRoute()

processLastCreatedRoute() 

Process the last created router in the stack.

processAvailableRoutes()

processAvailableRoutes() 

Process all routers in the stack that haven't been processed yet.

process()

process() : void

Process the the router.

Find if there is a match and take the appropriate action:

  • Execute an instance of a Closure
  • Resolve the requested Controller and method
  • Bind the passed data into the Closure function or class method
  • Filter routes to another Router or Closure

allowURLParameters()

allowURLParameters(  $params = array()) : self

Allow URL (GET) parameters/variables to be present in the URL of the route. Passing nothing or an empty array means any URL parameters are allowed.

Parameters

$params

Returns

self

secure()

secure() : self

Only allow match on route if request method was HTTPS.

Returns

self

auth()

auth(string|array  $session, null|string  $action = null) : self

Protect a route via the exsistence of a SESSION.

Parameters

string|array $session

Either the session name, or an array of session names.

null|string $action

a URI string to redirect to if the route matches and the user isn't authenticated.

Returns

self

filter()

filter(string  $uri, string|\Closure  $action = null) : self

Filter a url route using {*} notation.

Parameters

string $uri

The URI filter.

string|\Closure $action

The action to take if there is a match.

Returns

self

to()

to(string|array|\Closure  $r) : self

When a Router is used as a Filter and the filter matches there needs to be either a Router File or a Closure passed to handle the filtering.

Parameters

string|array|\Closure $r

A string representing a Router File, an array of routes, or a Closure.

Returns

self

get()

get(string  $uri, string|\Closure  $action) : self

Match a GET URI route.

Parameters

string $uri

The URI to match.

string|\Closure $action

The action to take if there is a match.

Returns

self

any()

any(string  $uri, string|\Closure  $action) : self

Match any URI route.

Parameters

string $uri

The URI to match.

string|\Closure $action

The action to take if there is a match.

Returns

self

post()

post(string  $uri, string|\Closure  $action) : self

Match a POST URI route.

Parameters

string $uri

The URI to match.

string|\Closure $action

The action to take if there is a match.

Returns

self

put()

put(string  $uri, string|\Closure  $action) : self

Match a PUT URI route.

Parameters

string $uri

The URI to match.

string|\Closure $action

The action to take if there is a match.

Returns

self

delete()

delete(string  $uri, string|\Closure  $action) : self

Match a DELETE URI route

Parameters

string $uri

The url to match.

string|\Closure $action

The action to take if there is a match.

Returns

self

multi()

multi(string  $uri, array  $actions) : self

Match a URI to multiple actions based on the request type.

Parameters

string $uri

The url to match.

array $actions

The possible actions for the match based on the current request type. For example if the request is a GET the actions array should contain a key get that points to a string (controller) or a Closure function..

Returns

self

paginate()

paginate(string  $uri, string|\Closure  $action) : self

Match a GET request that uses pagination.

Parameters

string $uri

The url to match.

string|\Closure $action

The action to take if there is a match.

Returns

self

where()

where(string|array  $k, null|string  $v = null) : void

Add where variables restrictions to the URI route.

Parameters

string|array $k

Either a string key or an array.

null|string $v

Either null or a string.

children()

children(array  $children) : \Disco\classes\self;

Routes that are children to the parent. The keys of the array (the URIs) are relative to the parent URI and will automatically have the parent URI prepended to them.

Parameters

array $children

The child routes (take the same form as children passed to self::processRouterArray).

Returns

\Disco\classes\self;

authenticated()

authenticated(  $auth) : boolean

Return whether or not the request is authenticated by a session.

Parameters

$auth

Returns

boolean

routeMatch()

routeMatch(boolean  $m = null) : boolean

Once a router has found a match we dont perform more match attempts.

This function is both a setter and a getter.

Parameters

boolean $m

Returns

boolean

resolveRouterPath()

resolveRouterPath(string  $routerPath) : string

Resolve a string name to a router file path. Can be as simple as say `user` which would map to `app/router/user.router.php` or aliased like `@shopping`.

Parameters

string $routerPath

The relative name of the router.

Throws

\Disco\exceptions\Exception

When no router file is found given the passed router path.

Returns

string —

The path to the router file.

useRouter()

useRouter(  $routerPath) : void

Load a Router File for processing.

Parameters

$routerPath

processRouterArray()

processRouterArray(array  $routes) : void

Process an array of routes.

A standard route is defined like so:

Array(
 '/uri/path/{var}' => Array(
     'type' (required) => string ('get','post','put','delete','multi','filter'),
     'action' (required) => string|\Closure|array,
     'where' (optional) => array,
     'allowURLParameters' (optional) => string|array,
     'auth' (optional) => Array(
         'session' (required) => string,
         'redirect' (optional) => string
     ),
     'secure' (optional) => boolean,
     'children' (optional) => array,
 )
)

Parameters

array $routes

The array of routes to process.

buildRelativeChildren()

buildRelativeChildren() 

Convert a children array of routes to use the parent routes information by prepending the parent URI to the childrens URIs and merge the childrens where variable restrictions with the parents where variable restrictions.

match()

match() : boolean

Base on the conditions established in the route, does the request URI match with the routes URI. Any variables that are extracted from the URI are stored in `$this->variables`.

Returns

boolean

filterMatch()

filterMatch(string  $uri,   $auth) : boolean

Filter a URI route against the $uri.

Parameters

string $uri

The URI to filter.

$auth

Returns

boolean

executeRoute()

executeRoute() : boolean

Execute the action (`$this->action`) specified by a route, either Closure or Controller Method passing in arguements from the URI appropriatly (`$this->variables`).

Returns

boolean

__routeMatch()

__routeMatch(boolean  $m = null) : boolean

Private method for setting and getting whether we have a route match yet. Big difference is that this method does not call `static::procesAvailableRoutes()` unlike its public counter part `routeMatch()`. The reason the public method calls `static::processAvailableRoutes()` is so that say a Router was created, and immeditatly after the a call is made to `Router::routeMatch()` to check if the last route satisifed the request, well if the `process()` method wasn't called on it directly, it wont be processed until another Router is created or the end of the application method `tearDown()` is called. So to make sure we respond with the correct anwser we need to make sure any un-processed routes are processed first.

Parameters

boolean $m

Returns

boolean