' . $exception->getLine() . ''
. '
'
. '' . nl2br(strip_tags($exception->getMessage())) . ''
. '
';
if ($exception instanceof Zend_Db_Statement_Exception
&& false !== ($lastQueryProfile = Qs_Db::getInstance()->getProfiler()->getLastQueryProfile())
) {
if (Qs_Request::isXmlHttpRequest()) {
$html .= "\nLast Query:\n" . Qs_SqlFormatter::format($lastQueryProfile->getQuery(), false);
} else {
$html .= '
Last query:
' . Qs_SqlFormatter::format($lastQueryProfile->getQuery());
}
}
return $html;
}
public static function getExceptionPlainMessage(Exception $exception)
{
$firstTracePoint = current($exception->getTrace());
$text = $firstTracePoint['class'] . $firstTracePoint['type'] . $firstTracePoint['function'] . ' '
. 'uncaught exception in ' . $exception->getFile() . ' on line ' . $exception->getLine() . ' - '
. strip_tags($exception->getMessage());
if ($exception instanceof Zend_Db_Statement_Exception
&& false !== ($lastQueryProfile = Qs_Db::getInstance()->getProfiler()->getLastQueryProfile())
) {
$text .= '. Last query: ' . $lastQueryProfile->getQuery();
}
return $text;
}
/**
* @param Exception $exception
* @return string
*/
public static function getExceptionBacktrace($exception)
{
$debugBacktrace = $exception->getTrace();
$debugBacktrace = Qs_Debug::_removeObjects($debugBacktrace);
return 'BACKTRACE
' . print_r($debugBacktrace, true) . '
';
}
protected function _sendExceptionNotification($exception)
{
$message = Qs_Debug::getExceptionMessage($exception);
$backtrace = Qs_Debug::getExceptionBacktrace($exception);
$html = $message
. '
'
. 'URL: ' . Qs_Request::getUrl() . '';
foreach (array('_GET', '_POST', '_COOKIE', '_SERVER', '_ENV') as $name) {
$html .= '
$' . $name . '
' . htmlspecialchars(print_r($GLOBALS[$name], true)) . '
';
}
$html .= '
' . $backtrace;
$notifyEmails = $this->getOption('notifyEmails');
if (is_array($notifyEmails) && !empty($notifyEmails)) {
$headers = 'From: debug@' . $_SERVER['SERVER_NAME'] . "\n"
. 'Reply-To: no-reply@' . $_SERVER['SERVER_NAME'] . "\n"
. 'Content-Type: text/html' . "\n"
. 'X-Mailer: PHP/' . phpversion();
foreach ($notifyEmails as $email) {
mail($email, 'Error Dump from ' . $_SERVER['SERVER_NAME'], $html, $headers);
}
}
return $this;
}
protected function _filterFilePaths($file)
{
if (!$this->_root) {
$this->_root = dirname(BASE_PATH);
}
return str_replace($this->_root . '/', '', $file);
}
/**
* @param Exception $exception
*/
public function exceptionHandler($exception)
{
self::logStdError('CMF Exception: ' . self::getExceptionPlainMessage($exception));
$message = Qs_Debug::getExceptionMessage($exception);
$backtrace = Qs_Debug::getExceptionBacktrace($exception);
$this->_sendExceptionNotification($exception);
$this->_writeLog([
'message' => $exception->getMessage(),
'exceptionCode' => $exception->getCode(),
'file' => $this->_filterFilePaths($exception->getFile()),
'line' => $exception->getLine(),
]);
if (Qs_Constant::get('DEBUG')) {
die($message . '
' . $backtrace);
}
die('Internal error');
}
public static function processException($exception)
{
Qs_Debug::getInstance()->exceptionHandler($exception);
}
public static function processExceptionSilent(Exception $exception)
{
Qs_Debug::getInstance()->silentExceptionHandler($exception);
}
public function silentExceptionHandler(Exception $exception)
{
$this->_writeLog([
'message' => $exception->getMessage(),
'exceptionCode' => $exception->getCode(),
'file' => $this->_filterFilePaths($exception->getFile()),
'line' => $exception->getLine(),
]);
$this->_sendExceptionNotification($exception);
}
public static function dumpSql($sql)
{
echo Qs_SqlFormatter::format('' . $sql);
}
}