From 94758dca763c4e042edf9e7ddea77dd1da60032b Mon Sep 17 00:00:00 2001 From: William Date: Fri, 16 Dec 2022 10:03:08 +0100 Subject: [PATCH] Fix the shitty errorhandler class --- app/WillySoft/Http/ErrorHandler.php | 40 ++++++++++++----------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/app/WillySoft/Http/ErrorHandler.php b/app/WillySoft/Http/ErrorHandler.php index 9025ca8..0ae8dc2 100644 --- a/app/WillySoft/Http/ErrorHandler.php +++ b/app/WillySoft/Http/ErrorHandler.php @@ -21,34 +21,28 @@ abstract class ErrorHandler public static function register(callable $callback) { ob_start(); - set_error_handler(self::error(...)); - set_exception_handler(self::exception(...)); - register_shutdown_function(self::shutdown(...), $callback); - } - private static function error($errno, $errstr, $errfile, $errline) - { - $errstr = htmlspecialchars($errstr); - self::$error_messages[] = "Error[$errno]: $errstr in $errfile at line $errline"; - } + set_error_handler(function($errno, $errstr, $errfile, $errline) { + $errstr = htmlspecialchars($errstr); + self::$error_messages[] = "Error[$errno]: $errstr in $errfile at line $errline"; + }); - private static function exception($exception) - { - self::$error_messages[] = "Uncaught Exception: " . $exception; - } + set_exception_handler(function($exception) { + self::$error_messages[] = "Uncaught Exception: " . $exception; + }); - private static function shutdown(callable $callback) - { - if (!self::$error_messages) { - return; - } + register_shutdown_function(function() use(&$callback) { + if (!self::$error_messages) { + return; + } - // remove current output to be replaced by error page - ob_end_clean(); + // remove current output to be replaced by error page + ob_end_clean(); - http_response_code(500); - header_remove(); + http_response_code(500); + header_remove(); - $callback(self::$error_messages); + $callback(self::$error_messages); + }); } } \ No newline at end of file