Error handling: Rename renderers to formatters

Refs #1641.
This commit is contained in:
Franz Liedke 2019-08-20 17:48:09 +02:00 committed by Daniël Klabbers
parent d45bf04341
commit ae59bf549f
10 changed files with 19 additions and 19 deletions

View File

@ -16,8 +16,8 @@ use Flarum\Foundation\AbstractServiceProvider;
use Flarum\Foundation\Application;
use Flarum\Foundation\ErrorHandling\Registry;
use Flarum\Foundation\ErrorHandling\Reporter;
use Flarum\Foundation\ErrorHandling\ViewRenderer;
use Flarum\Foundation\ErrorHandling\WhoopsRenderer;
use Flarum\Foundation\ErrorHandling\ViewFormatter;
use Flarum\Foundation\ErrorHandling\WhoopsFormatter;
use Flarum\Foundation\Event\ClearingCache;
use Flarum\Frontend\AddLocaleAssets;
use Flarum\Frontend\AddTranslations;
@ -55,7 +55,7 @@ class AdminServiceProvider extends AbstractServiceProvider
// All requests should first be piped through our global error handler
$pipe->pipe(new HttpMiddleware\HandleErrors(
$app->make(Registry::class),
$app->inDebugMode() ? $app->make(WhoopsRenderer::class) : $app->make(ViewRenderer::class),
$app->inDebugMode() ? $app->make(WhoopsFormatter::class) : $app->make(ViewFormatter::class),
$app->tagged(Reporter::class)
));

View File

@ -18,7 +18,7 @@ use Flarum\Event\ConfigureMiddleware;
use Flarum\Event\ConfigureNotificationTypes;
use Flarum\Foundation\AbstractServiceProvider;
use Flarum\Foundation\Application;
use Flarum\Foundation\ErrorHandling\JsonApiRenderer;
use Flarum\Foundation\ErrorHandling\JsonApiFormatter;
use Flarum\Foundation\ErrorHandling\Registry;
use Flarum\Foundation\ErrorHandling\Reporter;
use Flarum\Http\Middleware as HttpMiddleware;
@ -50,7 +50,7 @@ class ApiServiceProvider extends AbstractServiceProvider
$pipe->pipe(new HttpMiddleware\HandleErrors(
$app->make(Registry::class),
$app->make(JsonApiRenderer::class),
$app->make(JsonApiFormatter::class),
$app->tagged(Reporter::class)
));

View File

@ -10,7 +10,7 @@
namespace Flarum\Api;
use Exception;
use Flarum\Foundation\ErrorHandling\JsonApiRenderer;
use Flarum\Foundation\ErrorHandling\JsonApiFormatter;
use Flarum\Foundation\ErrorHandling\Registry;
use Flarum\User\User;
use Illuminate\Contracts\Container\Container;
@ -77,7 +77,7 @@ class Client
throw $e;
}
return (new JsonApiRenderer)->format($error, $request);
return (new JsonApiFormatter)->format($error, $request);
}
}
}

View File

@ -18,8 +18,8 @@ use Flarum\Foundation\AbstractServiceProvider;
use Flarum\Foundation\Application;
use Flarum\Foundation\ErrorHandling\Registry;
use Flarum\Foundation\ErrorHandling\Reporter;
use Flarum\Foundation\ErrorHandling\ViewRenderer;
use Flarum\Foundation\ErrorHandling\WhoopsRenderer;
use Flarum\Foundation\ErrorHandling\ViewFormatter;
use Flarum\Foundation\ErrorHandling\WhoopsFormatter;
use Flarum\Foundation\Event\ClearingCache;
use Flarum\Frontend\AddLocaleAssets;
use Flarum\Frontend\AddTranslations;
@ -65,7 +65,7 @@ class ForumServiceProvider extends AbstractServiceProvider
// All requests should first be piped through our global error handler
$pipe->pipe(new HttpMiddleware\HandleErrors(
$app->make(Registry::class),
$app->inDebugMode() ? $app->make(WhoopsRenderer::class) : $app->make(ViewRenderer::class),
$app->inDebugMode() ? $app->make(WhoopsFormatter::class) : $app->make(ViewFormatter::class),
$app->tagged(Reporter::class)
));

View File

@ -14,7 +14,7 @@ namespace Flarum\Foundation\ErrorHandling;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
interface Formatter
interface HttpFormatter
{
public function format(HandledError $error, Request $request): Response;
}

View File

@ -16,7 +16,7 @@ use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Tobscure\JsonApi\Document;
class JsonApiRenderer implements Formatter
class JsonApiFormatter implements HttpFormatter
{
public function format(HandledError $error, Request $request): Response
{

View File

@ -18,7 +18,7 @@ use Psr\Http\Message\ServerRequestInterface as Request;
use Symfony\Component\Translation\TranslatorInterface;
use Zend\Diactoros\Response\HtmlResponse;
class ViewRenderer implements Formatter
class ViewFormatter implements HttpFormatter
{
/**
* @var ViewFactory

View File

@ -15,7 +15,7 @@ use Franzl\Middleware\Whoops\WhoopsRunner;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
class WhoopsRenderer implements Formatter
class WhoopsFormatter implements HttpFormatter
{
public function format(HandledError $error, Request $request): Response
{

View File

@ -11,7 +11,7 @@
namespace Flarum\Http\Middleware;
use Flarum\Foundation\ErrorHandling\Formatter;
use Flarum\Foundation\ErrorHandling\HttpFormatter;
use Flarum\Foundation\ErrorHandling\Registry;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
@ -27,7 +27,7 @@ class HandleErrors implements Middleware
protected $registry;
/**
* @var Formatter
* @var HttpFormatter
*/
protected $formatter;
@ -36,7 +36,7 @@ class HandleErrors implements Middleware
*/
protected $reporters;
public function __construct(Registry $registry, Formatter $formatter, array $reporters)
public function __construct(Registry $registry, HttpFormatter $formatter, array $reporters)
{
$this->registry = $registry;
$this->formatter = $formatter;

View File

@ -12,7 +12,7 @@ namespace Flarum\Install;
use Flarum\Foundation\AppInterface;
use Flarum\Foundation\ErrorHandling\Registry;
use Flarum\Foundation\ErrorHandling\Reporter;
use Flarum\Foundation\ErrorHandling\WhoopsRenderer;
use Flarum\Foundation\ErrorHandling\WhoopsFormatter;
use Flarum\Http\Middleware\DispatchRoute;
use Flarum\Http\Middleware\HandleErrors;
use Flarum\Http\Middleware\StartSession;
@ -40,7 +40,7 @@ class Installer implements AppInterface
$pipe = new MiddlewarePipe;
$pipe->pipe(new HandleErrors(
$this->container->make(Registry::class),
$this->container->make(WhoopsRenderer::class),
$this->container->make(WhoopsFormatter::class),
$this->container->tagged(Reporter::class)
));
$pipe->pipe($this->container->make(StartSession::class));