class ControllerCollection

Builds Silex controllers.

It acts as a staging area for routes. You are able to set the route name until flush() is called, at which point all controllers are frozen and converted to a RouteCollection.

__call() forwards method-calls to Route, but returns instance of ControllerCollection listing Route's methods below, so that IDEs know they are valid

Properties

protected $controllers
protected $defaultRoute
protected $defaultController
protected $prefix
protected $routesFactory
protected $controllersFactory

Methods

__construct(Route $defaultRoute, RouteCollection $routesFactory = null, $controllersFactory = null)

No description

mount(string $prefix, ControllerCollection|callable $controllers)

Mounts controllers under the given route prefix.

match(string $pattern, mixed $to = null)

Maps a pattern to a callable.

get(string $pattern, mixed $to = null)

Maps a GET request to a callable.

post(string $pattern, mixed $to = null)

Maps a POST request to a callable.

put(string $pattern, mixed $to = null)

Maps a PUT request to a callable.

delete(string $pattern, mixed $to = null)

Maps a DELETE request to a callable.

options(string $pattern, mixed $to = null)

Maps an OPTIONS request to a callable.

patch(string $pattern, mixed $to = null)

Maps a PATCH request to a callable.

__call($method, $arguments)

No description

RouteCollection
flush()

Persists and freezes staged controllers.

ControllerCollection
assert(string $variable, string $regexp)

No description

ControllerCollection
value(string $variable, mixed $default)

No description

ControllerCollection
convert(string $variable, mixed $callback)

No description

ControllerCollection
method(string $method)

No description

ControllerCollection
requireHttp()

No description

ControllerCollection
requireHttps()

No description

ControllerCollection
before(mixed $callback)

No description

ControllerCollection
after(mixed $callback)

No description

ControllerCollection
when(string $condition)

No description

Details

at line 49
__construct(Route $defaultRoute, RouteCollection $routesFactory = null, $controllersFactory = null)

Parameters

Route $defaultRoute
RouteCollection $routesFactory
$controllersFactory

at line 67
mount(string $prefix, ControllerCollection|callable $controllers)

Mounts controllers under the given route prefix.

Parameters

string $prefix The route prefix
ControllerCollection|callable $controllers A ControllerCollection instance or a callable for defining routes

Exceptions

LogicException

at line 92
Controller match(string $pattern, mixed $to = null)

Maps a pattern to a callable.

You can optionally specify HTTP methods that should be matched.

Parameters

string $pattern Matched route pattern
mixed $to Callback that returns the response when matched

Return Value

Controller

at line 110
Controller get(string $pattern, mixed $to = null)

Maps a GET request to a callable.

Parameters

string $pattern Matched route pattern
mixed $to Callback that returns the response when matched

Return Value

Controller

at line 123
Controller post(string $pattern, mixed $to = null)

Maps a POST request to a callable.

Parameters

string $pattern Matched route pattern
mixed $to Callback that returns the response when matched

Return Value

Controller

at line 136
Controller put(string $pattern, mixed $to = null)

Maps a PUT request to a callable.

Parameters

string $pattern Matched route pattern
mixed $to Callback that returns the response when matched

Return Value

Controller

at line 149
Controller delete(string $pattern, mixed $to = null)

Maps a DELETE request to a callable.

Parameters

string $pattern Matched route pattern
mixed $to Callback that returns the response when matched

Return Value

Controller

at line 162
Controller options(string $pattern, mixed $to = null)

Maps an OPTIONS request to a callable.

Parameters

string $pattern Matched route pattern
mixed $to Callback that returns the response when matched

Return Value

Controller

at line 175
Controller patch(string $pattern, mixed $to = null)

Maps a PATCH request to a callable.

Parameters

string $pattern Matched route pattern
mixed $to Callback that returns the response when matched

Return Value

Controller

at line 180
__call($method, $arguments)

Parameters

$method
$arguments

at line 200
RouteCollection flush()

Persists and freezes staged controllers.

Return Value

RouteCollection A RouteCollection instance

at line 40
ControllerCollection assert(string $variable, string $regexp)

Parameters

string $variable
string $regexp

Return Value

ControllerCollection

at line 40
ControllerCollection value(string $variable, mixed $default)

Parameters

string $variable
mixed $default

Return Value

ControllerCollection

at line 40
ControllerCollection convert(string $variable, mixed $callback)

Parameters

string $variable
mixed $callback

Return Value

ControllerCollection

at line 40
ControllerCollection method(string $method)

Parameters

string $method

Return Value

ControllerCollection

at line 40
ControllerCollection requireHttp()

Return Value

ControllerCollection

at line 40
ControllerCollection requireHttps()

Return Value

ControllerCollection

at line 40
ControllerCollection before(mixed $callback)

Parameters

mixed $callback

Return Value

ControllerCollection

at line 40
ControllerCollection after(mixed $callback)

Parameters

mixed $callback

Return Value

ControllerCollection

at line 40
ControllerCollection when(string $condition)

Parameters

string $condition

Return Value

ControllerCollection