22 private static $fatalErrors = [E_USER_ERROR =>
'', E_RECOVERABLE_ERROR =>
''];
24 private static $logger =
null;
32 set_error_handler([$this,
'handleError']);
33 if ($setExceptionHandler) {
34 set_exception_handler([$this,
'handleException']);
36 if (self::$logger ==
null) {
47 debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
48 $trace = ob_get_contents();
52 $trace = preg_replace(
'/^#0\s+'.__FUNCTION__.
"[^\n]*\n/",
'', $trace, 1);
66 public function handleError($errno, $errstr, $errfile, $errline) {
67 $errorIsEnabled = (bool)($errno & ini_get(
'error_reporting'));
70 if(isset(self::$fatalErrors[$errno]) && $errorIsEnabled) {
71 throw new \ErrorException($errstr, 0, $errno, $errfile, $errline);
75 else if($errorIsEnabled) {
76 $info = $errstr.
" in ".$errfile.
" on line ".$errline;
77 self::$logger->logByErrorType($errno, $info);
86 self::$logger->error($ex);
__construct($setExceptionHandler=false)
Constructor.
static getStackTrace()
Get the stack trace.
handleError($errno, $errstr, $errfile, $errline)
Error handler.
static getLogger($name)
Get the logger with the given name.
handleException($ex)
Exception handler.
ErrorHandler catches all php errors and transforms fatal errors into ErrorExceptions and non-fatal in...