• Fabien Potencier's avatar
    made controller methods (before, after, ...) extensible · 3fd92830
    Fabien Potencier authored
    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 class accordingly:
    
        $this['route_class'] = 'MyRoute';
    
    or change the "route_factory" if you need to pass some arguments to the
    route constructor:
    
        $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.
    3fd92830
FunctionalTest.php 1.44 KB