mirror of
https://github.com/flarum/framework.git
synced 2025-02-27 14:00:53 +08:00
More cleanup and fixes
This commit is contained in:
parent
f5fbaf46a9
commit
827366fa9c
@ -14,11 +14,8 @@ use Flarum\Frontend\Frontend;
|
|||||||
use Flarum\Http\Content\NotAuthenticated;
|
use Flarum\Http\Content\NotAuthenticated;
|
||||||
use Flarum\Http\Content\NotFound;
|
use Flarum\Http\Content\NotFound;
|
||||||
use Flarum\Http\Content\PermissionDenied;
|
use Flarum\Http\Content\PermissionDenied;
|
||||||
use Flarum\Settings\SettingsRepositoryInterface;
|
|
||||||
use Illuminate\Contracts\Container\Container;
|
|
||||||
use Psr\Http\Message\ResponseInterface as Response;
|
use Psr\Http\Message\ResponseInterface as Response;
|
||||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||||
use Symfony\Component\Translation\TranslatorInterface;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This formatter will route certain errors to the SPA frontend.
|
* This formatter will route certain errors to the SPA frontend.
|
||||||
@ -37,16 +34,14 @@ class FrontendFormatter implements HttpFormatter
|
|||||||
|
|
||||||
public function format(HandledError $error, Request $request): Response
|
public function format(HandledError $error, Request $request): Response
|
||||||
{
|
{
|
||||||
$frontend = $this->container->make('flarum.frontend.forum');
|
|
||||||
|
|
||||||
if ($error->getStatusCode() === 401) {
|
if ($error->getStatusCode() === 401) {
|
||||||
$frontend->content(new NotAuthenticated);
|
$this->frontend->content(new NotAuthenticated);
|
||||||
} elseif ($error->getStatusCode() === 403) {
|
} elseif ($error->getStatusCode() === 403) {
|
||||||
$frontend->content(new PermissionDenied);
|
$this->frontend->content(new PermissionDenied);
|
||||||
} elseif ($error->getStatusCode() === 404) {
|
} elseif ($error->getStatusCode() === 404) {
|
||||||
$frontend->content(new NotFound);
|
$this->frontend->content(new NotFound);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (new Controller($frontend))->handle($request)->withStatus($error->getStatusCode());
|
return (new Controller($this->frontend))->handle($request)->withStatus($error->getStatusCode());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@ use Flarum\Foundation\ErrorHandling\FrontendFormatter;
|
|||||||
use Flarum\Foundation\ErrorHandling\Registry;
|
use Flarum\Foundation\ErrorHandling\Registry;
|
||||||
use Flarum\Foundation\ErrorHandling\Reporter;
|
use Flarum\Foundation\ErrorHandling\Reporter;
|
||||||
use Flarum\Foundation\ErrorHandling\WhoopsFormatter;
|
use Flarum\Foundation\ErrorHandling\WhoopsFormatter;
|
||||||
use Flarum\Frontend\Frontend;
|
|
||||||
use Flarum\Http\Exception\RouteNotFoundException;
|
use Flarum\Http\Exception\RouteNotFoundException;
|
||||||
use Flarum\User\Exception\NotAuthenticatedException;
|
use Flarum\User\Exception\NotAuthenticatedException;
|
||||||
use Flarum\User\Exception\PermissionDeniedException;
|
use Flarum\User\Exception\PermissionDeniedException;
|
||||||
@ -84,17 +83,11 @@ class HttpServiceProvider extends AbstractServiceProvider
|
|||||||
$this->container->singleton('flarum.http.frontend_handler', function () {
|
$this->container->singleton('flarum.http.frontend_handler', function () {
|
||||||
return new Middleware\HandleErrors(
|
return new Middleware\HandleErrors(
|
||||||
$this->container->make(Registry::class),
|
$this->container->make(Registry::class),
|
||||||
$this->container['flarum']->inDebugMode() ? $this->container->make(WhoopsFormatter::class) : $this->container->make(FrontendFormatter::class),
|
$this->container['flarum']->inDebugMode() ? $this->container->make(WhoopsFormatter::class) : new FrontendFormatter($this->container->make('flarum.frontend.forum')),
|
||||||
$this->container->tagged(Reporter::class),
|
$this->container->tagged(Reporter::class),
|
||||||
$this->container->make('flarum.http.frontend_exceptions')
|
$this->container->make('flarum.http.frontend_exceptions')
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->container->when(FrontendFormatter::class)
|
|
||||||
->needs(Frontend::class)
|
|
||||||
->give(function () {
|
|
||||||
return $this->container->make('flarum.frontend.forum');
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user