mirror of
https://github.com/flarum/core.git
synced 2025-10-12 15:34:26 +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:
@@ -11,13 +11,23 @@
|
||||
|
||||
namespace Flarum\Admin;
|
||||
|
||||
use Flarum\Admin\Middleware\RequireAdministrateAbility;
|
||||
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 AdminServiceProvider extends AbstractServiceProvider
|
||||
{
|
||||
@@ -33,6 +43,29 @@ class AdminServiceProvider extends AbstractServiceProvider
|
||||
$this->app->singleton('flarum.admin.routes', function () {
|
||||
return new RouteCollection;
|
||||
});
|
||||
|
||||
$this->app->singleton('flarum.admin.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));
|
||||
$pipe->pipe($app->make(RequireAdministrateAbility::class));
|
||||
|
||||
event(new ConfigureMiddleware($pipe, 'admin'));
|
||||
|
||||
$pipe->pipe($app->make(DispatchRoute::class, ['routes' => $app->make('flarum.admin.routes')]));
|
||||
|
||||
return $pipe;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -1,58 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* (c) Toby Zerner <toby.zerner@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Admin;
|
||||
|
||||
use Flarum\Event\ConfigureMiddleware;
|
||||
use Flarum\Foundation\Application;
|
||||
use Flarum\Http\AbstractServer;
|
||||
use Flarum\Http\Middleware\HandleErrors;
|
||||
use Zend\Stratigility\MiddlewarePipe;
|
||||
|
||||
class Server extends AbstractServer
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getMiddleware(Application $app)
|
||||
{
|
||||
$pipe = new MiddlewarePipe;
|
||||
$pipe->raiseThrowables();
|
||||
|
||||
if ($app->isInstalled()) {
|
||||
$path = parse_url($app->url('admin'), PHP_URL_PATH);
|
||||
$errorDir = __DIR__.'/../../error';
|
||||
|
||||
// All requests should first be piped through our global error handler
|
||||
$debugMode = ! $app->isUpToDate() || $app->inDebugMode();
|
||||
$pipe->pipe($path, new HandleErrors($errorDir, $app->make('log'), $debugMode));
|
||||
|
||||
if ($app->isUpToDate()) {
|
||||
$pipe->pipe($path, $app->make('Flarum\Http\Middleware\ParseJsonBody'));
|
||||
$pipe->pipe($path, $app->make('Flarum\Http\Middleware\StartSession'));
|
||||
$pipe->pipe($path, $app->make('Flarum\Http\Middleware\RememberFromCookie'));
|
||||
$pipe->pipe($path, $app->make('Flarum\Http\Middleware\AuthenticateWithSession'));
|
||||
$pipe->pipe($path, $app->make('Flarum\Http\Middleware\SetLocale'));
|
||||
$pipe->pipe($path, $app->make('Flarum\Admin\Middleware\RequireAdministrateAbility'));
|
||||
|
||||
event(new ConfigureMiddleware($pipe, $path, $this));
|
||||
|
||||
$pipe->pipe($path, $app->make('Flarum\Http\Middleware\DispatchRoute', ['routes' => $app->make('flarum.admin.routes')]));
|
||||
} else {
|
||||
$app->register('Flarum\Update\UpdateServiceProvider');
|
||||
|
||||
$pipe->pipe($path, $app->make('Flarum\Http\Middleware\DispatchRoute', ['routes' => $app->make('flarum.update.routes')]));
|
||||
}
|
||||
}
|
||||
|
||||
return $pipe;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user