introduce a series of optimizations on Routing
This pull request introduce a series of optimizations on Routing, and some improvements which enhance the abilities of the end-user to control the Routing behavior.
The notable improvements are the ability to pass custom data to a Route and the Route Filters definition also as a array, i.e.
Router::post('login', array(
'filters' => array('guest', 'csrf'),
'uses' => 'App\Modules\Users\Controllers\Authorize@postLogin'
));
As example for passing custom data to a Route could be, in future:
Route::get('admin/shiny-things/(:any)', array(
'filters' => array('auth', 'roles'), // A 'roles' Filter must be specified
'uses' => 'App\Controllers\Admin\ShinyThings@index',
'roles' => array('administrator', 'manager') // Only an administrator, or a manager can access this route
));
This route could be used together with a (theoretical now) Route Filter like:
// Roles-based Authorization Filter.
Route::filter('roles', function($route) {
$action = $route->getAction();
$roles = array_get($action, 'roles');
if (! is_null($roles) && ! Auth::user()->hasRole($roles)) {
$status = __('You are not authorized to access this resource.');
return Redirect::to('admin/dashboard')->withStatus($status, 'warning');
}
});
Finally, to note that this pull request doesn't introduce any API breaks.