mirror of
https://github.com/flarum/core.git
synced 2025-07-24 02:01:19 +02:00
Improve forum route registration API
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
<?php namespace Flarum\Events;
|
<?php namespace Flarum\Events;
|
||||||
|
|
||||||
use Flarum\Http\RouteCollection;
|
use Flarum\Http\RouteCollection;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
|
||||||
class RegisterForumRoutes
|
class RegisterForumRoutes
|
||||||
{
|
{
|
||||||
@@ -16,4 +17,24 @@ class RegisterForumRoutes
|
|||||||
{
|
{
|
||||||
$this->routes = $routes;
|
$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);
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user