class Route extends Route

Class Route

Base on Symfony Route, but for route collections with prefixes Tomahawk strips off the end slash to normalise rout matching based on URL

Methods

__construct(string $path, array $defaults = array(), array $requirements = array(), array $options = array(), string $host = '', string|array $schemes = array(), string|array $methods = array(), string $condition = null)

Constructor.

string
serialize()

Serialise route information to an array

unserialize(string $serialized)

Set route information from array of data

string
getPath()

Returns the pattern for the path.

setPath(string $pattern)

Sets the pattern for the path.

string
getHost()

Returns the pattern for the host.

setHost(string $pattern)

Sets the pattern for the host.

array
getSchemes()

Returns the lowercased schemes this route is restricted to.

setSchemes(string|array $schemes)

Sets the schemes (e.g. 'https') this route is restricted to.

bool
hasScheme(string $scheme)

Checks if a scheme requirement has been set.

array
getMethods()

Returns the uppercased HTTP methods this route is restricted to.

setMethods(string|array $methods)

Sets the HTTP methods (e.g. 'POST') this route is restricted to.

array
getOptions()

Returns the options.

setOptions(array $options)

Sets the options.

addOptions(array $options)

Adds options.

setOption(string $name, mixed $value)

Sets an option value.

mixed
getOption(string $name)

Get an option value.

bool
hasOption(string $name)

Checks if an option has been set

array
getDefaults()

Returns the defaults.

setDefaults(array $defaults)

Sets the defaults.

addDefaults(array $defaults)

Adds defaults.

mixed
getDefault(string $name)

Gets a default value.

bool
hasDefault(string $name)

Checks if a default value is set for the given variable.

setDefault(string $name, mixed $default)

Sets a default value.

array
getRequirements()

Returns the requirements.

setRequirements(array $requirements)

Sets the requirements.

addRequirements(array $requirements)

Adds requirements.

string|null
getRequirement(string $key)

Returns the requirement for the given key.

bool
hasRequirement(string $key)

Checks if a requirement is set for the given key.

setRequirement(string $key, string $regex)

Sets a requirement for the given key.

string
getCondition()

Returns the condition.

setCondition(string $condition)

Sets the condition.

CompiledRoute
compile()

Compiles the route.

$this
where($parameter, $pattern)

Set a pattern for a parameter

$this
setDefaultParameter($name, $value)

Set a default for a parameter

Details

at line 88
__construct(string $path, array $defaults = array(), array $requirements = array(), array $options = array(), string $host = '', string|array $schemes = array(), string|array $methods = array(), string $condition = null)

Constructor.

Available options:

  • compiler_class: A class name able to compile this route instance (RouteCompiler by default)

Parameters

string $path The path pattern to match
array $defaults An array of default parameter values
array $requirements An array of requirements for parameters (regexes)
array $options An array of options
string $host The host pattern to match
string|array $schemes A required URI scheme or an array of restricted schemes
string|array $methods A required HTTP method or an array of restricted methods
string $condition A condition that should evaluate to true for the route to match

at line 105
string serialize()

Serialise route information to an array

Return Value

string

at line 125
unserialize(string $serialized)

Set route information from array of data

Parameters

string $serialized

at line 149
string getPath()

Returns the pattern for the path.

Return Value

string The path pattern

at line 163
Route setPath(string $pattern)

Sets the pattern for the path.

This method implements a fluent interface.

Parameters

string $pattern The path pattern

Return Value

Route The current Route instance

at line 178
string getHost()

Returns the pattern for the host.

Return Value

string The host pattern

at line 192
Route setHost(string $pattern)

Sets the pattern for the host.

This method implements a fluent interface.

Parameters

string $pattern The host pattern

Return Value

Route The current Route instance

at line 206
array getSchemes()

Returns the lowercased schemes this route is restricted to.

So an empty array means that any scheme is allowed.

Return Value

array The schemes

at line 221
Route setSchemes(string|array $schemes)

Sets the schemes (e.g. 'https') this route is restricted to.

So an empty array means that any scheme is allowed.

This method implements a fluent interface.

Parameters

string|array $schemes The scheme or an array of schemes

Return Value

Route The current Route instance

at line 236
bool hasScheme(string $scheme)

Checks if a scheme requirement has been set.

Parameters

string $scheme

Return Value

bool true if the scheme requirement exists, otherwise false

at line 247
array getMethods()

Returns the uppercased HTTP methods this route is restricted to.

So an empty array means that any method is allowed.

Return Value

array The schemes

at line 262
Route setMethods(string|array $methods)

Sets the HTTP methods (e.g. 'POST') this route is restricted to.

So an empty array means that any method is allowed.

This method implements a fluent interface.

Parameters

string|array $methods The method or an array of methods

Return Value

Route The current Route instance

at line 275
array getOptions()

Returns the options.

Return Value

array The options

at line 289
Route setOptions(array $options)

Sets the options.

This method implements a fluent interface.

Parameters

array $options The options

Return Value

Route The current Route instance

at line 307
Route addOptions(array $options)

Adds options.

This method implements a fluent interface.

Parameters

array $options The options

Return Value

Route The current Route instance

at line 329
Route setOption(string $name, mixed $value)

Sets an option value.

This method implements a fluent interface.

Parameters

string $name An option name
mixed $value The option value

Return Value

Route The current Route instance

at line 344
mixed getOption(string $name)

Get an option value.

Parameters

string $name An option name

Return Value

mixed The option value or null when not given

at line 356
bool hasOption(string $name)

Checks if an option has been set

Parameters

string $name An option name

Return Value

bool true if the option is set, false otherwise

at line 366
array getDefaults()

Returns the defaults.

Return Value

array The defaults

at line 380
Route setDefaults(array $defaults)

Sets the defaults.

This method implements a fluent interface.

Parameters

array $defaults The defaults

Return Value

Route The current Route instance

at line 396
Route addDefaults(array $defaults)

Adds defaults.

This method implements a fluent interface.

Parameters

array $defaults The defaults

Return Value

Route The current Route instance

at line 413
mixed getDefault(string $name)

Gets a default value.

Parameters

string $name A variable name

Return Value

mixed The default value or null when not given

at line 425
bool hasDefault(string $name)

Checks if a default value is set for the given variable.

Parameters

string $name A variable name

Return Value

bool true if the default value is set, false otherwise

at line 440
Route setDefault(string $name, mixed $default)

Sets a default value.

Parameters

string $name A variable name
mixed $default The default value

Return Value

Route The current Route instance

at line 453
array getRequirements()

Returns the requirements.

Return Value

array The requirements

at line 467
Route setRequirements(array $requirements)

Sets the requirements.

This method implements a fluent interface.

Parameters

array $requirements The requirements

Return Value

Route The current Route instance

at line 483
Route addRequirements(array $requirements)

Adds requirements.

This method implements a fluent interface.

Parameters

array $requirements The requirements

Return Value

Route The current Route instance

at line 500
string|null getRequirement(string $key)

Returns the requirement for the given key.

Parameters

string $key The key

Return Value

string|null The regex or null when not given

at line 512
bool hasRequirement(string $key)

Checks if a requirement is set for the given key.

Parameters

string $key A variable name

Return Value

bool true if a requirement is specified, false otherwise

at line 527
Route setRequirement(string $key, string $regex)

Sets a requirement for the given key.

Parameters

string $key The key
string $regex The regex

Return Value

Route The current Route instance

at line 540
string getCondition()

Returns the condition.

Return Value

string The condition

at line 554
Route setCondition(string $condition)

Sets the condition.

This method implements a fluent interface.

Parameters

string $condition The condition

Return Value

Route The current Route instance

at line 572
CompiledRoute compile()

Compiles the route.

Return Value

CompiledRoute A CompiledRoute instance

Exceptions

LogicException If the Route cannot be compiled because the path or host pattern is invalid

See also

RouteCompiler which is responsible for the compilation process

at line 590
$this where($parameter, $pattern)

Set a pattern for a parameter

Parameters

$parameter
$pattern

Return Value

$this

at line 603
$this setDefaultParameter($name, $value)

Set a default for a parameter

Parameters

$name
$value

Return Value

$this