mirror of
https://github.com/flarum/framework.git
synced 2025-01-20 18:17:31 +08:00
Improve forum route registration API
This commit is contained in:
parent
314846d9a2
commit
57f55c2dd6
|
@ -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);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user