fabpot/Silex — pull request #376 by fabpot (2012-06-17 15:19:50+00:00)
Title: made controller methods (before, after, ...) extensible

You can now add your own methods on controllers (like the built-in
after, before, convert, ...) by defining your own Route class:

class MyRoute extends Route
{
public function secure($roles, $app)
{
// do something
}
}

and then change the "route_factory" accordingly:

$this['route_factory'] = function () {
return new MyRoute();
};

If you want to benefit from the new methods in a custom controller
collection, pass an instance of your Route to the ControllerCollection
constructor:

$controllers = new ControllerCollection(new MyRoute());

or even better, use the "controllers_factory" service:

$controllers = $app['controllers_factory'];

The limitation is that you can only have one custom Route class in an
Application. But this PR is just the first step. Thanks to PHP 5.4 and
the new traits support, the next pull request will use this new
refactoring to provide traits that you will be able to add to your
custom Application Route class.