mirror of
https://github.com/flarum/core.git
synced 2025-10-18 10:16:09 +02:00
Get rid of Server classes for Admin, API and Forum
The various middleware can be registered in the service provider, and the rest of the logic can all go through one single front controller (index.php in flarum/flarum, and Flarum\Http\Server in flarum/core). This will also simplify the necessary server setup, as only one rewrite rule remains.
This commit is contained in:
@@ -12,13 +12,22 @@
|
||||
namespace Flarum\Forum;
|
||||
|
||||
use Flarum\Event\ConfigureForumRoutes;
|
||||
use Flarum\Event\ConfigureMiddleware;
|
||||
use Flarum\Extension\Event\Disabled;
|
||||
use Flarum\Extension\Event\Enabled;
|
||||
use Flarum\Foundation\AbstractServiceProvider;
|
||||
use Flarum\Http\Middleware\AuthenticateWithSession;
|
||||
use Flarum\Http\Middleware\DispatchRoute;
|
||||
use Flarum\Http\Middleware\HandleErrors;
|
||||
use Flarum\Http\Middleware\ParseJsonBody;
|
||||
use Flarum\Http\Middleware\RememberFromCookie;
|
||||
use Flarum\Http\Middleware\SetLocale;
|
||||
use Flarum\Http\Middleware\StartSession;
|
||||
use Flarum\Http\RouteCollection;
|
||||
use Flarum\Http\RouteHandlerFactory;
|
||||
use Flarum\Http\UrlGenerator;
|
||||
use Flarum\Settings\Event\Saved;
|
||||
use Zend\Stratigility\MiddlewarePipe;
|
||||
|
||||
class ForumServiceProvider extends AbstractServiceProvider
|
||||
{
|
||||
@@ -34,6 +43,28 @@ class ForumServiceProvider extends AbstractServiceProvider
|
||||
$this->app->singleton('flarum.forum.routes', function () {
|
||||
return new RouteCollection;
|
||||
});
|
||||
|
||||
$this->app->singleton('flarum.forum.middleware', function ($app) {
|
||||
$pipe = new MiddlewarePipe;
|
||||
$pipe->raiseThrowables();
|
||||
|
||||
// All requests should first be piped through our global error handler
|
||||
$debugMode = ! $app->isUpToDate() || $app->inDebugMode();
|
||||
$errorDir = __DIR__.'/../../error';
|
||||
$pipe->pipe(new HandleErrors($errorDir, $app->make('log'), $debugMode));
|
||||
|
||||
$pipe->pipe($app->make(ParseJsonBody::class));
|
||||
$pipe->pipe($app->make(StartSession::class));
|
||||
$pipe->pipe($app->make(RememberFromCookie::class));
|
||||
$pipe->pipe($app->make(AuthenticateWithSession::class));
|
||||
$pipe->pipe($app->make(SetLocale::class));
|
||||
|
||||
event(new ConfigureMiddleware($pipe, 'forum'));
|
||||
|
||||
$pipe->pipe($app->make(DispatchRoute::class, ['routes' => $app->make('flarum.forum.routes')]));
|
||||
|
||||
return $pipe;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user