1
0
mirror of https://github.com/flarum/core.git synced 2025-07-29 20:50:28 +02:00

Allow manipulating error handler through extender

By giving each middleware a name, they can now be replaced or moved
around using the Middleware extender.

Fixes #2115.
This commit is contained in:
Franz Liedke
2020-05-24 08:47:10 +02:00
parent 4b6864534b
commit 63397bb466
3 changed files with 24 additions and 17 deletions

View File

@@ -44,6 +44,7 @@ class ApiServiceProvider extends AbstractServiceProvider
$this->app->singleton('flarum.api.middleware', function () {
return [
'flarum.api.error_handler',
HttpMiddleware\ParseJsonBody::class,
Middleware\FakeHttpMethods::class,
HttpMiddleware\StartSession::class,
@@ -55,14 +56,16 @@ class ApiServiceProvider extends AbstractServiceProvider
];
});
$this->app->singleton('flarum.api.handler', function () {
$pipe = new MiddlewarePipe;
$pipe->pipe(new HttpMiddleware\HandleErrors(
$this->app->bind('flarum.api.error_handler', function () {
return new HttpMiddleware\HandleErrors(
$this->app->make(Registry::class),
new JsonApiFormatter($this->app['flarum']->inDebugMode()),
$this->app->tagged(Reporter::class)
));
);
});
$this->app->singleton('flarum.api.handler', function () {
$pipe = new MiddlewarePipe;
foreach ($this->app->make('flarum.api.middleware') as $middleware) {
$pipe->pipe($this->app->make($middleware));