Fix the shitty errorhandler class
This commit is contained in:
parent
6d44c0a986
commit
94758dca76
@ -21,24 +21,17 @@ abstract class ErrorHandler
|
|||||||
public static function register(callable $callback)
|
public static function register(callable $callback)
|
||||||
{
|
{
|
||||||
ob_start();
|
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)
|
set_error_handler(function($errno, $errstr, $errfile, $errline) {
|
||||||
{
|
|
||||||
$errstr = htmlspecialchars($errstr);
|
$errstr = htmlspecialchars($errstr);
|
||||||
self::$error_messages[] = "<b>Error[$errno]:</b> $errstr in <b>$errfile</b> at line <b>$errline</b>";
|
self::$error_messages[] = "<b>Error[$errno]:</b> $errstr in <b>$errfile</b> at line <b>$errline</b>";
|
||||||
}
|
});
|
||||||
|
|
||||||
private static function exception($exception)
|
set_exception_handler(function($exception) {
|
||||||
{
|
|
||||||
self::$error_messages[] = "<b>Uncaught Exception:</b> " . $exception;
|
self::$error_messages[] = "<b>Uncaught Exception:</b> " . $exception;
|
||||||
}
|
});
|
||||||
|
|
||||||
private static function shutdown(callable $callback)
|
register_shutdown_function(function() use(&$callback) {
|
||||||
{
|
|
||||||
if (!self::$error_messages) {
|
if (!self::$error_messages) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -50,5 +43,6 @@ abstract class ErrorHandler
|
|||||||
header_remove();
|
header_remove();
|
||||||
|
|
||||||
$callback(self::$error_messages);
|
$callback(self::$error_messages);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user