class Route extends Route

A wrapper for a controller, mapped to a route.

Methods

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

Constructor.

run(callable $to)

Sets the route code that should be executed when matched.

assert(string $variable, string $regexp)

Sets the requirement for a route variable.

value(string $variable, mixed $default)

Sets the default value for a route variable.

convert(string $variable, mixed $callback)

Sets a converter for a route variable.

method(string $method)

Sets the requirement for the HTTP method.

host(string $host)

Sets the requirement of host on this Route.

requireHttp()

Sets the requirement of HTTP (no HTTPS) on this Route.

requireHttps()

Sets the requirement of HTTPS on this Route.

before(mixed $callback)

Sets a callback to handle before triggering the route callback.

after(mixed $callback)

Sets a callback to handle after the route callback.

when(string $condition)

Sets a condition for the route to match.

Details

at line 38
__construct(string $path = '/', array $defaults = array(), array $requirements = array(), array $options = array(), string $host = '', string|array $schemes = array(), string|array $methods = array())

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

at line 51
Route run(callable $to)

Sets the route code that should be executed when matched.

Parameters

callable $to PHP callback that returns the response when matched

Return Value

Route $this The current Route instance

at line 66
Route assert(string $variable, string $regexp)

Sets the requirement for a route variable.

Parameters

string $variable The variable name
string $regexp The regexp to apply

Return Value

Route $this The current route instance

at line 81
Route value(string $variable, mixed $default)

Sets the default value for a route variable.

Parameters

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

Return Value

Route $this The current Route instance

at line 96
Route convert(string $variable, mixed $callback)

Sets a converter for a route variable.

Parameters

string $variable The variable name
mixed $callback A PHP callback that converts the original value

Return Value

Route $this The current Route instance

at line 112
Route method(string $method)

Sets the requirement for the HTTP method.

Parameters

string $method The HTTP method name. Multiple methods can be supplied, delimited by a pipe character '|', eg. 'GET|POST'

Return Value

Route $this The current Route instance

at line 126
Route host(string $host)

Sets the requirement of host on this Route.

Parameters

string $host The host for which this route should be enabled

Return Value

Route $this The current Route instance

at line 138
Route requireHttp()

Sets the requirement of HTTP (no HTTPS) on this Route.

Return Value

Route $this The current Route instance

at line 150
Route requireHttps()

Sets the requirement of HTTPS on this Route.

Return Value

Route $this The current Route instance

at line 164
Route before(mixed $callback)

Sets a callback to handle before triggering the route callback.

Parameters

mixed $callback A PHP callback to be triggered when the Route is matched, just before the route callback

Return Value

Route $this The current Route instance

at line 180
Route after(mixed $callback)

Sets a callback to handle after the route callback.

Parameters

mixed $callback A PHP callback to be triggered after the route callback

Return Value

Route $this The current Route instance

at line 196
Route when(string $condition)

Sets a condition for the route to match.

Parameters

string $condition The condition

Return Value

Route $this The current Route instance