* @license PHP License * @package WB * @subpackage base */ /** * Error handling to avoid ugly output * * * * @version 0.2.1 * @package WB * @subpackage base */ class WBErrorHandler extends WBStdClass { /** * the message just before everything stops * @var string */ protected $msgFatal = 'Something really wicked happend...'; /** * end process * * Caution: this function does not return at all! */ protected function kill() { if (!class_exists('WBResponse', false)) { echo $this->msgFatal . "\n"; exit(1); } $request = WBClass::create('WBRequest'); $response = WBClass::create('WBResponse'); $response->setStatus(500); $response->add($this->msgFatal); $response->send($request); exit(1); } /** * check whether logging faicilty is on * * Usually, one just would load the logger class and start logging. But this * may result in more PHP-errors and therefore cause infinite recursion. * Hence, just log, if logger is already there... * * @return bool true in case logger is used */ protected function checkLogger() { if( class_exists( 'WBLog', false ) ) { return true; } return false; } /** * log backtrace message * * Transform backtrace into * * @param array $backtrace stack * @return void */ protected function logBacktrace( $backtrace ) { $logger = WBLog::start( 'error' ); $i = 0; foreach( $backtrace as $t ) { ++$i; $call = $t['function'] . '()'; if( isset( $t['class'] ) ) { $call = $t['class'] . $t['type'] . $call; } if( !isset( $t['file'] ) ) { $t['file'] = 'unknown'; } if( !isset( $t['line'] ) ) { $t['line'] = 'unknown'; } // convert arguments to strings $args = array(); if( isset( $t['args'] ) ) { foreach( $t['args'] as $a ) { if( is_object( $a ) ) { $args[] = get_class( $a ); break; } if( is_string( $a ) ) { $args[] = "'" . $a . "'"; break; } if( is_numeric( $a ) ) { $args[] = $a; break; } if( is_bool( $a ) ) { if( $a ) { $args[] = 'true'; break; } $args[] = 'false'; break; } if( is_null( $a ) ) { $args[] = 'null'; break; } } } $tLog = array( 'type' => 'backtrace', 'no' => $i, 'call' => $call, 'args' => implode( ', ', $args ), 'file' => $t['file'], 'line' => $t['line'], ); $logger->debug( $tLog ); } return; } } ?>