Improve forum route registration API

This commit is contained in:
Toby Zerner 2015-07-22 10:04:22 +09:30
parent 314846d9a2
commit 57f55c2dd6

View File

@ -1,6 +1,7 @@
<?php namespace Flarum\Events;
use Flarum\Http\RouteCollection;
use Psr\Http\Message\ServerRequestInterface;
class RegisterForumRoutes
{
@ -16,4 +17,24 @@ class RegisterForumRoutes
{
$this->routes = $routes;
}
public function get($url, $name, $action = 'Flarum\Forum\Actions\IndexAction')
{
$this->route('get', $url, $name, $action);
}
protected function route($method, $url, $name, $action)
{
$this->routes->$method($url, $name, $this->action($action));
}
protected function action($class)
{
return function (ServerRequestInterface $httpRequest, $routeParams) use ($class) {
/** @var \Flarum\Support\Action $action */
$action = app($class);
return $action->handle($httpRequest, $routeParams);
};
}
}