From 499ff85f63809bd3eebf99ba538c5f40fc92b853 Mon Sep 17 00:00:00 2001 From: Maarten Date: Tue, 3 Mar 2020 20:20:35 +0100 Subject: [PATCH] Simplify ExceptionHandler --- src/Runtime/Exceptions/ExceptionHandler.php | 26 ++++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/Runtime/Exceptions/ExceptionHandler.php b/src/Runtime/Exceptions/ExceptionHandler.php index a14528e..65ae4c6 100644 --- a/src/Runtime/Exceptions/ExceptionHandler.php +++ b/src/Runtime/Exceptions/ExceptionHandler.php @@ -52,19 +52,27 @@ class ExceptionHandler { }); } else { - self::$handler->pushHandler(new PrettyPageHandler()); - } - - if (Misc::isAjaxRequest()){ - self::$handler->pushHandler(new JsonResponseHandler()); - } - - if (Misc::isCommandLine()){ - self::$handler->pushHandler(new PlainTextHandler()); + self::$handler->pushHandler(self::handler()); } self::$handler->register(); } + /** + * @return Handler + */ + private static function handler() + { + if (Misc::isAjaxRequest()){ + return new JsonResponseHandler(); + } + + if (Misc::isCommandLine()){ + return new PlainTextHandler(); + } + + return new PrettyPageHandler(); + } + }