/** * A method to convert PEAR_Error objects to strings. * * @static * @param PEAR_Error $oError A {@link PEAR_Error} object */ function errorObjToString($oError, $additionalInfo = null) { $aConf = $GLOBALS['_MAX']['CONF']; $message = htmlspecialchars($oError->getMessage()); $debugInfo = htmlspecialchars($oError->getDebugInfo()); $backtrace = htmlspecialchars($oError->getBacktrace()); $additionalInfo = htmlspecialchars($additionalInfo); $level = $oError->getCode(); $errorType = MAX::errorConstantToString($level); $img = MAX::constructURL(MAX_URL_IMAGE, 'errormessage.gif'); // Message $output = <<<EOF <br /> <div class="errormessage"> <img class="errormessage" src="{$img}" align="absmiddle"> <span class='tab-r'>{$errorType} Error</span> <br /> <br />{$message} <br /><pre>{$debugInfo}</pre> {$additionalInfo} </div> <br /> <br /> EOF; return $output; }
/** * Return a trace for the PEAR error. * * @param PEAR_Error $error The PEAR error. * * @return string The backtrace as a string. */ private function _getPearTrace(PEAR_Error $error) { $backtrace = $error->getBacktrace(); if (!empty($backtrace)) { $pear_error = "\n\n" . 'PEAR Error:' . "\n"; foreach ($backtrace as $frame) { $pear_error .= ' ' . (isset($frame['class']) ? $frame['class'] : '') . (isset($frame['type']) ? $frame['type'] : '') . (isset($frame['function']) ? $frame['function'] : 'unkown') . ' ' . (isset($frame['file']) ? $frame['file'] : 'unkown') . ':' . (isset($frame['line']) ? $frame['line'] : 'unkown') . "\n"; } $pear_error .= "\n"; return $pear_error; } return ''; }
/** * @param PEAR_Error $error */ public function __construct(PEAR_Error $error) { $message = $error->getMessage(); $userInfo = $error->getUserInfo(); if (!is_null($userInfo)) { $message .= ', ' . $userInfo; } parent::__construct($message); $backtrace = $error->getBacktrace(); if (is_array($backtrace)) { $this->file = $backtrace[1]['file']; $this->line = $backtrace[1]['line']; } }
/** * Return a trace for the PEAR error. * * @param PEAR_Error $error The PEAR error. * * @return string The backtrace as a string. */ private function _getPearTrace(PEAR_Error $error) { $pear_error = ''; $backtrace = $error->getBacktrace(); if (!empty($backtrace)) { $pear_error .= 'PEAR backtrace:' . "\n\n"; foreach ($backtrace as $frame) { $pear_error .= (isset($frame['class']) ? $frame['class'] : '') . (isset($frame['type']) ? $frame['type'] : '') . (isset($frame['function']) ? $frame['function'] : 'unkown') . ' ' . (isset($frame['file']) ? $frame['file'] : 'unkown') . ':' . (isset($frame['line']) ? $frame['line'] : 'unkown') . "\n"; } } $userinfo = $error->getUserInfo(); if (!empty($userinfo)) { $pear_error .= "\n" . 'PEAR user info:' . "\n\n"; if (is_string($userinfo)) { $pear_error .= $userinfo; } else { $pear_error .= print_r($userinfo, true); } } return $pear_error; }
/** * A callback function that sets the default PEAR Error behaviour. * * @static * @param PEAR_Error $oError A {@link PEAR_Error} object */ function pearErrorHandler($oError) { $aConf = $GLOBALS['_MAX']['CONF']; // Log message $message = $oError->getMessage(); $debugInfo = $oError->getDebugInfo(); OA::debug('PEAR' . " :: {$message} : {$debugInfo}", PEAR_LOG_ERR); // If sesssion debug, send error info to screen $msg = ''; if (empty($aConf['debug']['production'])) { $GLOBALS['_MAX']['ERRORS'][] = $oError; } // Add backtrace info if (!empty($aConf['debug']['showBacktrace'])) { $msg .= 'PEAR backtrace: <div onClick="if (this.style.height) {this.style.height = null;this.style.width = null;} else {this.style.height = \'8px\'; this.style.width=\'8px\'}"'; $msg .= 'style="float:left; cursor: pointer; border: 1px dashed #FF0000; background-color: #EFEFEF; height: 8px; width: 8px; overflow: hidden; margin-bottom: 2px;">'; $msg .= '<pre wrap style="margin: 5px; background-color: #EFEFEF">'; ob_start(); print_r($oError->getBacktrace()); $msg .= ob_get_clean(); $msg .= '<hr></pre></div>'; $msg .= '<div style="clear:both"></div>'; } if (defined('TEST_ENVIRONMENT_RUNNING')) { // It's a test, stop execution echo nl2br("Message: {$message}\ndebugInfo: {$debugInfo}\nbackTrace: {$msg}"); exit(1); } elseif (defined('OA_WEBSERVICES_API_XMLRPC')) { // It's an XML-RPC response $oResponse = new XML_RPC_Response('', 99999, $message); echo $oResponse->serialize(); exit; } else { // Send the error to the screen echo MAX::errorObjToString($oError, $msg); } }
/** * Push the error to the error stack. * * @param object $error PEAR_Error An error object * @return void * @access public * @static */ function push_error(PEAR_Error $error) { self::errorstack()->push($error->getCode(), 'error', array('object' => $error), $error->getMessage(), false, $error->getBacktrace()); }