* @copyright 2004 by http://wombat.exit0.net * @package wombatSite * @subpackage error */ /** * gsErrorHandler * - supports patError * * @version 1.0.0 * @package wombatSite * @subpackage error */ class wbErrorHandler { /** * store debug backtrace * @var int $_debug */ var $_backtrace = null; /** * store operation mode * @var int $_debug */ var $_debug = false; /** * message to be displayed on exit * @var int $_dieMessage */ var $_dieMessage; /** * constructor * * @access public */ function __construct() { $this->_dieMessage = _("Due to technical problems, this page cannot be displayed.\nSorry for any inconvinience"); } /** * PHP4 Wrappter for constructor * * @access public * @see __construct */ function wbErrorHandler() { $this->__construct(); } /** * handle php errors * * @access private * @param int $no * @param string $str * @param string $file * @param int $line * @see set_error_handler() */ function handlePhpError( $no, $str, $file, $line ) { $level = ''; switch( $no ) { case E_ERROR; case E_USER_ERROR; $level = 'Error'; break; case E_WARNING; case E_USER_WARNING; $level = 'Warning'; break; case E_NOTICE; case E_USER_NOTICE; $level = 'Notice'; break; case E_STRICT; return; $level = 'Strict'; break; default: $level = 'unknown error'; break; } if( wbDebugger::isActive() ) { $msg = sprintf( "%s \n [file: %s, line: %s]", $str, $file, $line ); wbDebugger::addMsg( $level, wbDebugger::sprint( $msg ), 'PHP-Error' ); if( function_exists( 'debug_backtrace' ) ) { $this->_backtrace = debug_backtrace(); $this->_addBacktrace2Debugger( $level, 'PHP-Error' ); } } if( $no == E_USER_ERROR || $no == E_ERROR ) { if( wbDebugger::isActive() ) { wbDebugger::printMsg(); } echo $this->_dieMessage; exit( 1 ); } } /** * handle patError Level: Error * * @access private * @param object $err patError-object * @param int $type E_ERROR (default), E_WARNING, E_NOTICE * @return boolean $result true on success */ function handlePatError( &$err, $type = E_ERROR ) { if( wbDebugger::isActive() ) { $level = patErrorManager::translateErrorLevel( $err->getLevel() ); $msg = sprintf( '%s [file: %s, line %s]', $err->getInfo(), $err->getFile(), $err->getLine()); wbDebugger::addMsg( $level, $err->getMessage(), $err->getCode() ); wbDebugger::addMsg( $level, $msg, '+++Info' ); } $this->_backtrace = $err->getBacktrace(); $this->_addBacktrace2Debugger( $level, $err->getMessage(), 'pat' ); switch( $type ) { case E_ERROR: if( wbDebugger::isActive() ) { wbDebugger::printMsg(); } echo wbDebugger::sprint( $this->_dieMessage ); exit( 1 ); break; case E_WARNING: case E_NOTICE: break; } return $err; } /** * handle patError Level: Warning * * @access private * @param object $err patError-object * @return boolean $result true on success */ function handlePatWarning( &$err ) { return $this->handlePatError( $err, E_WARNING ); } /** * handle patError Level: Notice * * @access private * @param object $err patError-object * @return boolean $result true on success * @uses handlePatError() */ function handlePatNotice( $err ) { return $this->handlePatError( $err, E_NOTICE ); } /** * add backtrace messages to debugger * * @access private * @return boolean $result true on success */ function _addBacktrace2Debugger( $level, $title, $src = 'php' ) { $j = 1; for( $i = count( $this->_backtrace ) - 1; $i > 0; --$i ) { $title = sprintf( '>>>%03d', $j ); $file = 'NA'; $type = 'NA'; $line = 'NA'; $class = 'NA'; $function = 'NA'; // $args = array(); if( isset( $this->_backtrace[$i]['class'] ) ) $class = $this->_backtrace[$i]['class']; if( strtolower( $class ) === 'paterrormanager' || strtolower( $class ) === 'paterror' ) { continue; } if( isset( $this->_backtrace[$i]['file'] ) ) $file = $this->_backtrace[$i]['file']; if( isset( $this->_backtrace[$i]['line'] ) ) $line = $this->_backtrace[$i]['line']; if( isset( $this->_backtrace[$i]['function'] ) ) $function = $this->_backtrace[$i]['function']; if( isset( $this->_backtrace[$i]['type'] ) ) $type = $this->_backtrace[$i]['type']; /* if( isset( $this->_backtrace[$i]['args'] ) ) { $args = $this->_backtrace[$i]['args']; } */ $msg = sprintf( 'File: %s, line: %s, class: %s, type: %s, function: %s' , $file , $line , $class , $type , $function ); wbDebugger::addMsg( $level, $msg, $title ); ++$j; } return true; } } ?>