improved error analysing regarding source class

This commit is contained in:
Steffen Schröder 2014-05-24 13:57:27 +02:00
parent 7830a017ad
commit 3e98adb4d6

View File

@ -207,11 +207,15 @@ class ErrorHandler {
}
$errorTag = $this->getErrorTag($errorNumber);
$sourceClass = null;
$traceSourceClass = null;
$message = $errorTag . ': ' . $errorString;
$fileLine = $errorFile . ': ' . $errorLine;
$traceString = $this->parseBackTrace(debug_backtrace(), $sourceClass);
$traceString = $this->parseBackTrace(array_slice(debug_backtrace(), 1), $traceSourceClass);
$sourceClass = $this->getSourceClass($errorFile);
if (!$sourceClass) {
$sourceClass = $traceSourceClass;
}
$logMessage = $message . PHP_EOL . 'File&Line: ' . $fileLine . PHP_EOL . 'Trace: ' . $traceString;
$this->maniaControl->log($logMessage);
@ -289,6 +293,27 @@ class ErrorHandler {
return "[PHP ERROR '{$errorLevel}']";
}
/**
* Get the Source Class via the Error File
*
* @param string $errorFile
* @return string
*/
private function getSourceClass($errorFile) {
if (!$errorFile) {
return null;
}
$filePath = substr($errorFile, strlen(ManiaControlDir));
$filePath = str_replace('plugins' . DIRECTORY_SEPARATOR, '', $filePath);
$filePath = str_replace('core' . DIRECTORY_SEPARATOR, '', $filePath);
$className = str_replace('.php', '', $filePath);
$className = str_replace(DIRECTORY_SEPARATOR, '\\', $className);
if (!class_exists($className, false)) {
return null;
}
return $className;
}
/**
* Check if the given Error Number is a User Error
*
@ -314,7 +339,7 @@ class ErrorHandler {
*/
public function handleShutdown() {
$error = error_get_last();
if ($error && ($error['type'] & E_FATAL)) {
if ($error) {
$this->handleError($error['type'], $error['message'], $error['file'], $error['line']);
}
}