\Horde_Routes_Route

The Route object holds a route recognition and generation routine.

See __construct() docs for usage.

Summary

Methods
Properties
Constants
__construct()
makeRegexp()
buildNextReg()
match()
generate()
$routePath
$encoding
$decodeErrors
$static
$filter
$absolute
$explicit
$defaults
$conditions
$maxKeys
$minKeys
$hardCoded
$reqs
$regexp
No constants found
_pathKeys()
_minKeys()
_defaults()
$_routeList
$_routeBackwards
$_splitChars
$_prior
$_reqRegs
$_memberName
$_collectionName
$_parentResource
N/A
No private methods found
No private properties found
N/A

Properties

$routePath

$routePath : string

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

Type

string

$encoding

$encoding : string

Encoding of this route (not yet supported)

Type

string

$decodeErrors

$decodeErrors : string

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

Type

string

$static

$static : string

Is this a static route?

Type

string

$filter

$filter : callback

Filter function to operate on arguments before generation

Type

callback

$absolute

$absolute : boolean

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

Type

boolean

$explicit

$explicit : boolean

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

Type

boolean

$defaults

$defaults : array

Default keyword arguments for this route

Type

array

$conditions

$conditions : array

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

Type

array

$maxKeys

$maxKeys : array

Maximum keys that this route could utilize.

Type

array

$minKeys

$minKeys : array

Minimum keys required to generate this route

Type

array

$hardCoded

$hardCoded : array

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

Type

array

$reqs

$reqs : array

Requirements for this route

Type

array

$regexp

$regexp : string

Regular expression for matching this route

Type

string

$_routeList

$_routeList : array

Route path split by '/'

Type

array

$_routeBackwards

$_routeBackwards : array

Reverse of $routeList

Type

array

$_splitChars

$_splitChars : array

Characters that split the parts of a URL

Type

array

$_prior

$_prior : string

Last path part used by buildNextReg()

Type

string

$_reqRegs

$_reqRegs : array

Requirements formatted as regexps suitable for preg_match()

Type

array

$_memberName

$_memberName : null|string

Member name if this is a RESTful route

Type

null|string

$_collectionName

$_collectionName : null|string

Collection name if this is a RESTful route

Type

null|string

$_parentResource

$_parentResource : string

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

Type

string

Methods

__construct()

__construct(  $routePath,   $kargs = array()) 

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

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
$kargs

makeRegexp()

makeRegexp(array  $clist) : void

Create the regular expression for matching.

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

array $clist

List of all possible controllers

buildNextReg()

buildNextReg(array  $path, array  $clist) : array

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

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

Parameters

array $path

The RouteList for the path

array $clist

List of all possible controllers

Returns

array —

[array, boolean, boolean]

match()

match(string  $url,   $kargs = array()) : null|array

Match a url to our regexp.

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

string $url

URL to match

$kargs

Returns

null|array —

Array of match data if matched, Null otherwise

generate()

generate(array  $kargs) 

Generate a URL from ourself given a set of keyword arguments

Parameters

array $kargs

Keyword arguments

_pathKeys()

_pathKeys(string  $routePath) : array

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

Parameters

string $routePath

Route path

Returns

array —

Route list

_minKeys()

_minKeys(array  $routeList) : array

Utility function to walk the route backwards

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

Parameters

array $routeList

Route path split by '/'

Returns

array —

[minimum keys for route, route list reversed]

_defaults()

_defaults(  $routeKeys, array  $reservedKeys, array  $kargs) : array

Creates a default array of strings

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 $reservedKeys

Array of keys not in the route path

array $kargs

Keyword args passed to the Route constructor

Returns

array —

[defaults, new default keys]