class Router

Class to create and parse routes

Constants

PROCESS_BEFORE

Mask for the before process stage

PROCESS_DURING

Mask for the during process stage

PROCESS_AFTER

Mask for the after process stage

Methods

__construct( array $options = array())

Class constructor

static  Router
getInstance( string $client, array $options = array())

Returns the global Router object, only creating it if it doesn't already exist.

array
parse( JUri $uri)

Function to convert a route to an internal URI

JUri
build( string $url)

Function to convert an internal URI to a route

integer
getMode()

Get the router mode

void
setMode( integer $mode)

Set the router mode

void
setVar( string $key, mixed $value, boolean $create = true)

Set a router variable, creating it if it doesn't exist

void
setVars( array $vars = array(), boolean $merge = true)

Set the router variable array

mixed
getVar( string $key)

Get a router variable

array
getVars()

Get the router variable array

void
attachBuildRule( callable $callback, string $stage = self::PROCESS_DURING)

Attach a build rule

void
attachParseRule( callable $callback, string $stage = self::PROCESS_DURING)

Attach a parse rule

Details

__construct( array $options = array())

Class constructor

Parameters

array $options Array of options

static Router getInstance( string $client, array $options = array())

Returns the global Router object, only creating it if it doesn't already exist.

Parameters

string $client The name of the client
array $options An associative array of options

Return Value

Router A Router object.

Exceptions

RuntimeException

array parse( JUri $uri)

Function to convert a route to an internal URI

Parameters

JUri $uri &$uri The uri.

Return Value

array

JUri build( string $url)

Function to convert an internal URI to a route

Parameters

string $url The internal URL or an associative array

Return Value

JUri The absolute search engine friendly URL object

integer getMode()

Get the router mode

Return Value

integer

void setMode( integer $mode)

Set the router mode

Parameters

integer $mode The routing mode.

Return Value

void

void setVar( string $key, mixed $value, boolean $create = true)

Set a router variable, creating it if it doesn't exist

Parameters

string $key The name of the variable
mixed $value The value of the variable
boolean $create If True, the variable will be created if it doesn't exist yet

Return Value

void

void setVars( array $vars = array(), boolean $merge = true)

Set the router variable array

Parameters

array $vars An associative array with variables
boolean $merge If True, the array will be merged instead of overwritten

Return Value

void

mixed getVar( string $key)

Get a router variable

Parameters

string $key The name of the variable

Return Value

mixed Value of the variable

array getVars()

Get the router variable array

Return Value

array An associative array of router variables

void attachBuildRule( callable $callback, string $stage = self::PROCESS_DURING)

Attach a build rule

Parameters

callable $callback The function to be called
string $stage The stage of the build process that this should be added to. Possible values: 'preprocess', '' for the main build process, 'postprocess'

Return Value

void

void attachParseRule( callable $callback, string $stage = self::PROCESS_DURING)

Attach a parse rule

Parameters

callable $callback The function to be called.
string $stage The stage of the parse process that this should be added to. Possible values: 'preprocess', '' for the main parse process, 'postprocess'

Return Value

void