1
0
mirror of https://github.com/flarum/core.git synced 2025-08-06 08:27:42 +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:
Franz Liedke
2017-06-30 12:07:20 +02:00
parent b4c7f8ca89
commit 69b517ea79
10 changed files with 263 additions and 318 deletions

View File

@@ -12,17 +12,28 @@
namespace Flarum\Api;
use Flarum\Api\Controller\AbstractSerializeController;
use Flarum\Api\Middleware\FakeHttpMethods;
use Flarum\Api\Middleware\HandleErrors;
use Flarum\Api\Serializer\AbstractSerializer;
use Flarum\Api\Serializer\NotificationSerializer;
use Flarum\Event\ConfigureApiRoutes;
use Flarum\Event\ConfigureMiddleware;
use Flarum\Event\ConfigureNotificationTypes;
use Flarum\Foundation\AbstractServiceProvider;
use Flarum\Http\Middleware\AuthenticateWithHeader;
use Flarum\Http\Middleware\AuthenticateWithSession;
use Flarum\Http\Middleware\DispatchRoute;
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 Tobscure\JsonApi\ErrorHandler;
use Tobscure\JsonApi\Exception\Handler\FallbackExceptionHandler;
use Tobscure\JsonApi\Exception\Handler\InvalidParameterExceptionHandler;
use Zend\Stratigility\MiddlewarePipe;
class ApiServiceProvider extends AbstractServiceProvider
{
@@ -39,6 +50,27 @@ class ApiServiceProvider extends AbstractServiceProvider
return new RouteCollection;
});
$this->app->singleton('flarum.api.middleware', function ($app) {
$pipe = new MiddlewarePipe;
$pipe->raiseThrowables();
$pipe->pipe($app->make(HandleErrors::class));
$pipe->pipe($app->make(ParseJsonBody::class));
$pipe->pipe($app->make(FakeHttpMethods::class));
$pipe->pipe($app->make(StartSession::class));
$pipe->pipe($app->make(RememberFromCookie::class));
$pipe->pipe($app->make(AuthenticateWithSession::class));
$pipe->pipe($app->make(AuthenticateWithHeader::class));
$pipe->pipe($app->make(SetLocale::class));
event(new ConfigureMiddleware($pipe, 'api'));
$pipe->pipe($app->make(DispatchRoute::class, ['routes' => $app->make('flarum.api.routes')]));
return $pipe;
});
$this->app->singleton(ErrorHandler::class, function () {
$handler = new ErrorHandler;