Documentation

Route
in package

The Route object holds a route recognition and generation routine.

See __construct() docs for usage.

Table of Contents

$absolute  : bool
Is this an absolute path? (Mapper will not prepend SCRIPT_NAME)
$conditions  : array<string|int, mixed>|null
Array of keyword args for special conditions (method, subDomain, function)
$decodeErrors  : string
What to do on decoding errors? 'ignore' or 'replace'
$defaults  : array<string|int, mixed>
Default keyword arguments for this route
$encoding  : string
Encoding of this route (not yet supported)
$explicit  : bool
Does this route use explicit mode (no implicit defaults)?
$filter  : callable
Filter function to operate on arguments before generation
$hardCoded  : array<string|int, mixed>
Default keywords that don't exist in the path; can't be changed by an incoming URL.
$maxKeys  : array<string|int, mixed>
Maximum keys that this route could utilize.
$minKeys  : array<string|int, mixed>
Minimum keys required to generate this route
$regexp  : string
Regular expression for matching this route
$reqs  : array<string|int, mixed>
Requirements for this route
$routePath  : string
The path for this route, such as ':controller/:action/:id'
$stack  : iteratable<string|int, mixed>|null
An environment of pre and post filters for the route
$static  : string
Is this a static route?
$_collectionName  : null|string
Collection name if this is a RESTful route
$_memberName  : null|string
Member name if this is a RESTful route
$_parentResource  : string
Name of the parent resource, if this is a RESTful route & has a parent
$_reqRegs  : array<string|int, mixed>
Requirements formatted as regexps suitable for preg_match()
$_routeBackwards  : array<string|int, mixed>
Reverse of $routeList
$_splitChars  : array<string|int, mixed>
Characters that split the parts of a URL
$prior  : string
Last path part used by buildNextReg()
$routeList  : array<string|int, mixed>
Route path split by '/'
__construct()  : mixed
Initialize a route, with a given routepath for matching/generation
buildNextReg()  : array<string|int, mixed>
Recursively build a regexp given a path, and a controller list.
generate()  : string|null
Generate a URL from ourself given a set of keyword arguments
makeRegexp()  : void
Create the regular expression for matching.
match()  : array<string|int, mixed>|null
Match a url to our regexp.
_defaults()  : array<string|int, mixed>
Creates a default array of strings
_minKeys()  : array<string|int, mixed>
Utility function to walk the route backwards
_pathKeys()  : array<string|int, mixed>
Utility method to walk the route, and pull out the valid dynamic/wildcard keys

Properties

$absolute

Is this an absolute path? (Mapper will not prepend SCRIPT_NAME)

public bool $absolute

$conditions

Array of keyword args for special conditions (method, subDomain, function)

public array<string|int, mixed>|null $conditions

$decodeErrors

What to do on decoding errors? 'ignore' or 'replace'

public string $decodeErrors = 'replace'

$defaults

Default keyword arguments for this route

public array<string|int, mixed> $defaults = []

$encoding

Encoding of this route (not yet supported)

public string $encoding = 'utf-8'

$explicit

Does this route use explicit mode (no implicit defaults)?

public bool $explicit

$filter

Filter function to operate on arguments before generation

public callable $filter

$hardCoded

Default keywords that don't exist in the path; can't be changed by an incoming URL.

public array<string|int, mixed> $hardCoded

$maxKeys

Maximum keys that this route could utilize.

public array<string|int, mixed> $maxKeys

$minKeys

Minimum keys required to generate this route

public array<string|int, mixed> $minKeys

$regexp

Regular expression for matching this route

public string $regexp

$reqs

Requirements for this route

public array<string|int, mixed> $reqs

$routePath

The path for this route, such as ':controller/:action/:id'

public string $routePath

$stack

An environment of pre and post filters for the route

public iteratable<string|int, mixed>|null $stack

$static

Is this a static route?

public string $static

$_collectionName

Collection name if this is a RESTful route

protected null|string $_collectionName
Tags
see
resource()

$_memberName

Member name if this is a RESTful route

protected null|string $_memberName
Tags
see
resource()

$_parentResource

Name of the parent resource, if this is a RESTful route & has a parent

protected string $_parentResource
Tags
see
resource

$_reqRegs

Requirements formatted as regexps suitable for preg_match()

protected array<string|int, mixed> $_reqRegs

$_routeBackwards

Reverse of $routeList

protected array<string|int, mixed> $_routeBackwards

$_splitChars

Characters that split the parts of a URL

protected array<string|int, mixed> $_splitChars

$prior

Last path part used by buildNextReg()

protected string $prior

$routeList

Route path split by '/'

protected array<string|int, mixed> $routeList

Methods

__construct()

Initialize a route, with a given routepath for matching/generation

public __construct(mixed $routePath[, mixed $kargs = [] ]) : mixed

The set of keyword args will be used as defaults.

Usage: $route = new Horde_Routes_Route(':controller/:action/:id');

$route = new Horde_Routes_Route('date/:year/:month/:day',
                array('controller'=>'blog', 'action'=>'view'));

$route = new Horde_Routes_Route('archives/:page',
                array('controller'=>'blog', 'action'=>'by_page',
                      'requirements' => array('page'=>'\d{1,2}'));

Note: Route is generally not called directly, a Mapper instance connect() method should be used to add routes.

Parameters
$routePath : mixed
$kargs : mixed = []
Return values
mixed

buildNextReg()

Recursively build a regexp given a path, and a controller list.

public buildNextReg(array<string|int, mixed> $path, array<string|int, mixed> $clist) : array<string|int, mixed>

Returns the regular expression string, and two booleans that can be ignored as they're only used internally by buildnextreg.

Parameters
$path : array<string|int, mixed>

The RouteList for the path

$clist : array<string|int, mixed>

List of all possible controllers

Return values
array<string|int, mixed>

[array, boolean, boolean]

generate()

Generate a URL from ourself given a set of keyword arguments

public generate(array<string|int, mixed> $kargs) : string|null
Parameters
$kargs : array<string|int, mixed>

Keyword arguments

Return values
string|null

Null if generation failed, URL otherwise

makeRegexp()

Create the regular expression for matching.

public makeRegexp(array<string|int, mixed> $clist) : void

Note: This MUST be called before match can function properly.

clist should be a list of valid controller strings that can be matched, for this reason makeregexp should be called by the web framework after it knows all available controllers that can be utilized.

Parameters
$clist : array<string|int, mixed>

List of all possible controllers

Return values
void

match()

Match a url to our regexp.

public match(string $url[, array<string|int, mixed> $kargs = [] ]) : array<string|int, mixed>|null

While the regexp might match, this operation isn't guaranteed as there's other factors that can cause a match to fail even though the regexp succeeds (Default that was relied on wasn't given, requirement regexp doesn't pass, etc.).

Therefore the calling function shouldn't assume this will return a valid dict, the other possible return is False if a match doesn't work out.

Parameters
$url : string

URL to match

$kargs : array<string|int, mixed> = []

Keyword arguments

Return values
array<string|int, mixed>|null

Array of match data if matched, Null otherwise

_defaults()

Creates a default array of strings

protected _defaults(array<string|int, mixed> $routeKeys, array<string|int, mixed> $reservedKeys, array<string|int, mixed> $kargs) : array<string|int, mixed>

Puts together the array of defaults, turns non-null values to strings, and add in our action/id default if they use and do not specify it

Precondition: $this->_defaultKeys is an array of the currently assumed default keys

Parameters
$routeKeys : array<string|int, mixed>

All the keys found in the route path

$reservedKeys : array<string|int, mixed>

Array of keys not in the route path

$kargs : array<string|int, mixed>

Keyword args passed to the Route constructor

Return values
array<string|int, mixed>

[defaults, new default keys]

_minKeys()

Utility function to walk the route backwards

protected _minKeys(array<string|int, mixed> $routeList) : array<string|int, mixed>

Will determine the minimum keys we must have to generate a working route.

Parameters
$routeList : array<string|int, mixed>

Route path split by '/'

Return values
array<string|int, mixed>

[minimum keys for route, route list reversed]

_pathKeys()

Utility method to walk the route, and pull out the valid dynamic/wildcard keys

protected _pathKeys(string $routePath) : array<string|int, mixed>
Parameters
$routePath : string

Route path

Return values
array<string|int, mixed>

Route list

Search results