error and exception handler class
This commit is contained in:
committed by
Steffen Schröder
parent
96a90b0b0c
commit
053649600d
@ -53,72 +53,6 @@ function logMessage($message) {
|
||||
echo $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the prefix for the given error level
|
||||
*
|
||||
* @param int $errorLevel
|
||||
* @return string
|
||||
*/
|
||||
function getErrorTag($errorLevel) {
|
||||
if ($errorLevel == E_NOTICE) {
|
||||
return '[PHP NOTICE]';
|
||||
}
|
||||
if ($errorLevel == E_WARNING) {
|
||||
return '[PHP WARNING]';
|
||||
}
|
||||
if ($errorLevel == E_ERROR) {
|
||||
return '[PHP ERROR]';
|
||||
}
|
||||
if ($errorLevel == E_USER_NOTICE) {
|
||||
return '[ManiaControl NOTICE]';
|
||||
}
|
||||
if ($errorLevel == E_USER_WARNING) {
|
||||
return '[ManiaControl WARNING]';
|
||||
}
|
||||
if ($errorLevel == E_USER_ERROR) {
|
||||
return '[ManiaControl ERROR]';
|
||||
}
|
||||
return "[PHP {$errorLevel}]";
|
||||
}
|
||||
|
||||
// Register error handler
|
||||
set_error_handler('errorHandler', -1);
|
||||
set_exception_handler('exceptionHandler');
|
||||
|
||||
/**
|
||||
* Error Handler
|
||||
*
|
||||
* @param $errorNumber
|
||||
* @param $errorString
|
||||
* @param $errorFile
|
||||
* @param $errorLine
|
||||
* @return bool
|
||||
*/
|
||||
function errorHandler($errorNumber, $errorString, $errorFile, $errorLine) {
|
||||
if (error_reporting() == 0) {
|
||||
// Error suppressed
|
||||
return false;
|
||||
}
|
||||
// Log error
|
||||
$errorTag = getErrorTag($errorNumber);
|
||||
$message = "{$errorTag}: {$errorString} in File '{$errorFile}' on Line {$errorLine}!";
|
||||
logMessage($message);
|
||||
if ($errorNumber == E_ERROR || $errorNumber == E_USER_ERROR) {
|
||||
logMessage('Stopping execution...');
|
||||
exit();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception Handler
|
||||
*
|
||||
* @param Exception $ex
|
||||
*/
|
||||
function exceptionHandler(Exception $ex) {
|
||||
$message = "[ManiaControl EXCEPTION]: {$ex->getMessage()} Trace: {$ex->getTraceAsString()}!";
|
||||
logMessage($message);
|
||||
}
|
||||
|
||||
// Autoload Function that loads ManiaControl Class Files on Demand
|
||||
spl_autoload_register(function ($className) {
|
||||
|
Reference in New Issue
Block a user