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 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.
added an exception when a method does not exist to ease debugging
added some unit tests
merged branch fabpot/route-factory (PR #376)

Commits
-------

c463a6e added some unit tests
e29c91e added an exception when a method does not exist to ease debugging
3fd9283 made controller methods (before, after, ...) extensible

Discussion
----------

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 (#378) uses this new
refactoring to provide traits that you can add to your
custom Application Route class.

---------------------------------------------------------------------------

by igorw at 2012-06-18T12:13:33Z

Looks good to me. One thing, what about a method_exists() in `__call` to give a better error message?

---------------------------------------------------------------------------

by fabpot at 2012-06-18T17:41:34Z

I've added an exception for when the method does not exist.

---------------------------------------------------------------------------

by fabpot at 2012-06-18T18:03:00Z

And now with some unit tests.

---------------------------------------------------------------------------

by igorw at 2012-06-18T18:33:33Z

:+1: