From 57f55c2dd63a450237d4d79b0d6406a926052e9d Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Wed, 22 Jul 2015 10:04:22 +0930 Subject: [PATCH] Improve forum route registration API --- src/Events/RegisterForumRoutes.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Events/RegisterForumRoutes.php b/src/Events/RegisterForumRoutes.php index d859930b5..0e7598644 100644 --- a/src/Events/RegisterForumRoutes.php +++ b/src/Events/RegisterForumRoutes.php @@ -1,6 +1,7 @@ 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); + }; + } }