applied common formatting
This commit is contained in:
@ -7,18 +7,18 @@ use ManiaControl\Update\UpdateManager;
|
||||
|
||||
/**
|
||||
* Error and Exception Manager Class
|
||||
*
|
||||
* @author steeffeen & kremsy
|
||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class ErrorHandler {
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
const MC_DEBUG_NOTICE = "ManiaControl.DebugNotice";
|
||||
const MC_DEBUG_NOTICE = "ManiaControl.DebugNotice";
|
||||
const SETTING_RESTART_ON_EXCEPTION = 'Automatically restart on Exceptions';
|
||||
|
||||
|
||||
/*
|
||||
* Private Properties
|
||||
*/
|
||||
@ -43,55 +43,52 @@ class ErrorHandler {
|
||||
|
||||
/**
|
||||
* ManiaControl ExceptionHandler
|
||||
*
|
||||
*
|
||||
* @param \Exception $ex
|
||||
* @param bool $shutdown
|
||||
* @param bool $shutdown
|
||||
*/
|
||||
public function exceptionHandler(\Exception $ex, $shutdown = true) {
|
||||
// Log exception
|
||||
$message = "[ManiaControl EXCEPTION]: {$ex->getMessage()}";
|
||||
$message = "[ManiaControl EXCEPTION]: {$ex->getMessage()}";
|
||||
$traceMessage = 'Class: ' . get_class($ex) . PHP_EOL;
|
||||
$traceMessage .= 'Trace:' . PHP_EOL . $ex->getTraceAsString();
|
||||
logMessage($message . PHP_EOL . $traceMessage);
|
||||
|
||||
|
||||
if ($this->reportErrors) {
|
||||
$error = array();
|
||||
$error["Type"] = "Exception";
|
||||
$error["Message"] = $message;
|
||||
$error["Backtrace"] = $traceMessage;
|
||||
$error = array();
|
||||
$error["Type"] = "Exception";
|
||||
$error["Message"] = $message;
|
||||
$error["Backtrace"] = $traceMessage;
|
||||
$error['OperatingSystem'] = php_uname();
|
||||
$error['PHPVersion'] = phpversion();
|
||||
|
||||
$error['PHPVersion'] = phpversion();
|
||||
|
||||
if ($this->maniaControl->server) {
|
||||
$error['ServerLogin'] = $this->maniaControl->server->login;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$error['ServerLogin'] = '';
|
||||
}
|
||||
|
||||
|
||||
if ($this->maniaControl->settingManager && $this->maniaControl->updateManager) {
|
||||
$error['UpdateChannel'] = $this->maniaControl->settingManager->getSetting($this->maniaControl->updateManager, UpdateManager::SETTING_UPDATECHECK_CHANNEL);
|
||||
$error['UpdateChannel'] = $this->maniaControl->settingManager->getSetting($this->maniaControl->updateManager, UpdateManager::SETTING_UPDATECHECK_CHANNEL);
|
||||
$error['ManiaControlVersion'] = $this->maniaControl->updateManager->getNightlyBuildDate();
|
||||
}
|
||||
else {
|
||||
$error['UpdateChannel'] = '';
|
||||
} else {
|
||||
$error['UpdateChannel'] = '';
|
||||
$error['ManiaControlVersion'] = ManiaControl::VERSION;
|
||||
}
|
||||
|
||||
|
||||
$json = json_encode($error);
|
||||
$info = base64_encode($json);
|
||||
|
||||
$url = ManiaControl::URL_WEBSERVICE . "errorreport?error=" . urlencode($info);
|
||||
|
||||
$url = ManiaControl::URL_WEBSERVICE . "errorreport?error=" . urlencode($info);
|
||||
$success = FileUtil::loadFile($url);
|
||||
|
||||
|
||||
if (!json_decode($success)) {
|
||||
logMessage("Exception-Report failed!");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
logMessage("Exception successfully reported!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($shutdown) {
|
||||
if ($this->shouldRestart()) {
|
||||
$this->maniaControl->restart();
|
||||
@ -100,9 +97,31 @@ class ErrorHandler {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if ManiaControl should restart automatically
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function shouldRestart() {
|
||||
if (!$this->maniaControl || !$this->maniaControl->settingManager) {
|
||||
return false;
|
||||
}
|
||||
$setting = $this->maniaControl->settingManager->getSetting($this, self::SETTING_RESTART_ON_EXCEPTION, true);
|
||||
return $setting;
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggers a Debug Notice to the ManiaControl Website
|
||||
*
|
||||
* @param $message
|
||||
*/
|
||||
public function triggerDebugNotice($message) {
|
||||
$this->errorHandler(self::MC_DEBUG_NOTICE, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Error Handler
|
||||
*
|
||||
*
|
||||
* @param $errorNumber
|
||||
* @param $errorString
|
||||
* @param $errorFile
|
||||
@ -114,52 +133,49 @@ class ErrorHandler {
|
||||
// Error suppressed
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$userError = $this->isUserErrorNumber($errorNumber);
|
||||
|
||||
|
||||
// Log error
|
||||
$errorTag = $this->getErrorTag($errorNumber);
|
||||
$message = $errorTag . ': ' . $errorString;
|
||||
$fileLine = $errorFile . ': ' . $errorLine;
|
||||
$errorTag = $this->getErrorTag($errorNumber);
|
||||
$message = $errorTag . ': ' . $errorString;
|
||||
$fileLine = $errorFile . ': ' . $errorLine;
|
||||
$traceMessage = $this->parseBackTrace(debug_backtrace());
|
||||
$logMessage = $message . PHP_EOL . ($userError ? $fileLine : $traceMessage);
|
||||
$logMessage = $message . PHP_EOL . ($userError ? $fileLine : $traceMessage);
|
||||
logMessage($logMessage);
|
||||
|
||||
|
||||
if ($this->reportErrors && !$userError) {
|
||||
$error = array();
|
||||
$error["Type"] = "Error";
|
||||
$error["Message"] = $message;
|
||||
$error["FileLine"] = $fileLine;
|
||||
$error["Backtrace"] = $traceMessage;
|
||||
$error = array();
|
||||
$error["Type"] = "Error";
|
||||
$error["Message"] = $message;
|
||||
$error["FileLine"] = $fileLine;
|
||||
$error["Backtrace"] = $traceMessage;
|
||||
$error['OperatingSystem'] = php_uname();
|
||||
$error['PHPVersion'] = phpversion();
|
||||
|
||||
$error['PHPVersion'] = phpversion();
|
||||
|
||||
if ($this->maniaControl->server) {
|
||||
$error['ServerLogin'] = $this->maniaControl->server->login;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$error['ServerLogin'] = '';
|
||||
}
|
||||
|
||||
|
||||
if ($this->maniaControl->settingManager && $this->maniaControl->updateManager) {
|
||||
$error['UpdateChannel'] = $this->maniaControl->settingManager->getSetting($this->maniaControl->updateManager, UpdateManager::SETTING_UPDATECHECK_CHANNEL);
|
||||
$error['UpdateChannel'] = $this->maniaControl->settingManager->getSetting($this->maniaControl->updateManager, UpdateManager::SETTING_UPDATECHECK_CHANNEL);
|
||||
$error['ManiaControlVersion'] = ManiaControl::VERSION . '#' . $this->maniaControl->updateManager->getNightlyBuildDate();
|
||||
}
|
||||
else {
|
||||
$error['UpdateChannel'] = '';
|
||||
} else {
|
||||
$error['UpdateChannel'] = '';
|
||||
$error['ManiaControlVersion'] = ManiaControl::VERSION;
|
||||
}
|
||||
|
||||
|
||||
$json = json_encode($error);
|
||||
$info = base64_encode($json);
|
||||
|
||||
$url = ManiaControl::URL_WEBSERVICE . "errorreport?error=" . urlencode($info);
|
||||
|
||||
$url = ManiaControl::URL_WEBSERVICE . "errorreport?error=" . urlencode($info);
|
||||
$success = FileUtil::loadFile($url);
|
||||
|
||||
|
||||
if (!json_decode($success)) {
|
||||
logMessage("Error-Report failed!");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
logMessage("Error successfully reported!");
|
||||
}
|
||||
}
|
||||
@ -172,7 +188,7 @@ class ErrorHandler {
|
||||
|
||||
/**
|
||||
* Check if the given Error Number is a User Error
|
||||
*
|
||||
*
|
||||
* @param int $errorNumber
|
||||
* @return bool
|
||||
*/
|
||||
@ -180,18 +196,9 @@ class ErrorHandler {
|
||||
return ($errorNumber === E_USER_ERROR || $errorNumber === E_USER_WARNING || $errorNumber === E_USER_NOTICE || $errorNumber === E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggers a Debug Notice to the ManiaControl Website
|
||||
*
|
||||
* @param $message
|
||||
*/
|
||||
public function triggerDebugNotice($message) {
|
||||
$this->errorHandler(self::MC_DEBUG_NOTICE, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Prefix for the given Error Level
|
||||
*
|
||||
*
|
||||
* @param int $errorLevel
|
||||
* @return string
|
||||
*/
|
||||
@ -229,36 +236,13 @@ class ErrorHandler {
|
||||
return "[PHP {$errorLevel}]";
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if ManiaControl should stop its Execution
|
||||
*
|
||||
* @param int $errorNumber
|
||||
* @return bool
|
||||
*/
|
||||
private function shouldStopExecution($errorNumber) {
|
||||
return ($errorNumber === E_ERROR || $errorNumber === E_USER_ERROR || $errorNumber === E_FATAL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if ManiaControl should restart automatically
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function shouldRestart() {
|
||||
if (!$this->maniaControl || !$this->maniaControl->settingManager) {
|
||||
return false;
|
||||
}
|
||||
$setting = $this->maniaControl->settingManager->getSetting($this, self::SETTING_RESTART_ON_EXCEPTION, true);
|
||||
return $setting;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the Debug Backtrace into a String for the Error Report
|
||||
* return string
|
||||
*/
|
||||
private function parseBackTrace(array $backtrace) {
|
||||
$traceString = 'Trace:';
|
||||
$stepCount = 0;
|
||||
$stepCount = 0;
|
||||
foreach ($backtrace as $traceStep) {
|
||||
$traceString .= PHP_EOL . '#' . $stepCount . ': ';
|
||||
if (isset($traceStep['class'])) {
|
||||
@ -282,4 +266,14 @@ class ErrorHandler {
|
||||
}
|
||||
return $traceString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if ManiaControl should stop its Execution
|
||||
*
|
||||
* @param int $errorNumber
|
||||
* @return bool
|
||||
*/
|
||||
private function shouldStopExecution($errorNumber) {
|
||||
return ($errorNumber === E_ERROR || $errorNumber === E_USER_ERROR || $errorNumber === E_FATAL);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user