Silex API
Class

Silex\Route

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.

Route run(callable $to)

Sets the route code that should be executed when matched.

Route assert(string $variable, string $regexp)

Sets the requirement for a route variable.

Route value(string $variable, mixed $default)

Sets the default value for a route variable.

Route convert(string $variable, mixed $callback)

Sets a converter for a route variable.

Route method(string $method)

Sets the requirement for the HTTP method.

Route host(string $host)

Sets the requirement of host on this Route.

Route requireHttp()

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

Route requireHttps()

Sets the requirement of HTTPS on this Route.

Route before(mixed $callback)

Sets a callback to handle before triggering the route callback.

Route after(mixed $callback)

Sets a callback to handle after the route callback.

Details

at line 38
public __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:

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
public 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
public 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
public 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
public 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
public 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
public 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
public Route requireHttp()

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

Return Value

Route $this The current Route instance

at line 150
public Route requireHttps()

Sets the requirement of HTTPS on this Route.

Return Value

Route $this The current Route instance

at line 164
public 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
public 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