Error handling: Rename renderers to formatters

Refs #1641.
This commit is contained in:
Franz Liedke 2019-08-20 17:48:09 +02:00
parent 8a74becdff
commit be5c1f6033
10 changed files with 19 additions and 19 deletions

View File

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

View File

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

View File

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

View File

@ -20,8 +20,8 @@ use Flarum\Foundation\AbstractServiceProvider;
use Flarum\Foundation\Application; use Flarum\Foundation\Application;
use Flarum\Foundation\ErrorHandling\Registry; use Flarum\Foundation\ErrorHandling\Registry;
use Flarum\Foundation\ErrorHandling\Reporter; use Flarum\Foundation\ErrorHandling\Reporter;
use Flarum\Foundation\ErrorHandling\ViewRenderer; use Flarum\Foundation\ErrorHandling\ViewFormatter;
use Flarum\Foundation\ErrorHandling\WhoopsRenderer; use Flarum\Foundation\ErrorHandling\WhoopsFormatter;
use Flarum\Foundation\Event\ClearingCache; use Flarum\Foundation\Event\ClearingCache;
use Flarum\Frontend\AddLocaleAssets; use Flarum\Frontend\AddLocaleAssets;
use Flarum\Frontend\AddTranslations; use Flarum\Frontend\AddTranslations;
@ -67,7 +67,7 @@ class ForumServiceProvider extends AbstractServiceProvider
// All requests should first be piped through our global error handler // All requests should first be piped through our global error handler
$pipe->pipe(new HttpMiddleware\HandleErrors( $pipe->pipe(new HttpMiddleware\HandleErrors(
$app->make(Registry::class), $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) $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\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Http\Message\ServerRequestInterface as Request;
interface Formatter interface HttpFormatter
{ {
public function format(HandledError $error, Request $request): Response; 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 Psr\Http\Message\ServerRequestInterface as Request;
use Tobscure\JsonApi\Document; use Tobscure\JsonApi\Document;
class JsonApiRenderer implements Formatter class JsonApiFormatter implements HttpFormatter
{ {
public function format(HandledError $error, Request $request): Response 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 Symfony\Component\Translation\TranslatorInterface;
use Zend\Diactoros\Response\HtmlResponse; use Zend\Diactoros\Response\HtmlResponse;
class ViewRenderer implements Formatter class ViewFormatter implements HttpFormatter
{ {
/** /**
* @var ViewFactory * @var ViewFactory

View File

@ -15,7 +15,7 @@ use Franzl\Middleware\Whoops\WhoopsRunner;
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;
class WhoopsRenderer implements Formatter class WhoopsFormatter implements HttpFormatter
{ {
public function format(HandledError $error, Request $request): Response public function format(HandledError $error, Request $request): Response
{ {

View File

@ -11,7 +11,7 @@
namespace Flarum\Http\Middleware; namespace Flarum\Http\Middleware;
use Flarum\Foundation\ErrorHandling\Formatter; use Flarum\Foundation\ErrorHandling\HttpFormatter;
use Flarum\Foundation\ErrorHandling\Registry; use Flarum\Foundation\ErrorHandling\Registry;
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;
@ -27,7 +27,7 @@ class HandleErrors implements Middleware
protected $registry; protected $registry;
/** /**
* @var Formatter * @var HttpFormatter
*/ */
protected $formatter; protected $formatter;
@ -36,7 +36,7 @@ class HandleErrors implements Middleware
*/ */
protected $reporters; protected $reporters;
public function __construct(Registry $registry, Formatter $formatter, array $reporters) public function __construct(Registry $registry, HttpFormatter $formatter, array $reporters)
{ {
$this->registry = $registry; $this->registry = $registry;
$this->formatter = $formatter; $this->formatter = $formatter;

View File

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