* @license PHP License * @package WB * @subpackage base */ /** * specific handler for PAT errors * * @version 0.2.0 * @package WB * @subpackage base */ class WBErrorHandler_Pat extends WBErrorHandler { /** * backtrace stack * @var array */ protected $backtrace = array(); /** * Static constructor * * Sets up error handler */ static public function staticConstruct() { WBClass::load( 'patErrorManager' ); $me = new WBErrorHandler_Pat(); WBErrorHandler_Php::expect('Non-static method patErrorManager::setErrorHandling()'); patErrorManager::setErrorHandling(E_ERROR, 'callback', array($me, 'handleError' )); WBErrorHandler_Php::expect('Non-static method patErrorManager::setErrorHandling()'); patErrorManager::setErrorHandling(E_WARNING, 'callback', array($me, 'handleWarning')); WBErrorHandler_Php::expect('Non-static method patErrorManager::setErrorHandling()'); //patErrorManager::setErrorHandling(E_NOTICE, 'ignore'); patErrorManager::setErrorHandling(E_NOTICE, 'callback', array($me, 'handleNotice')); } /** * handle patError Level: Notice * * @param object $err patError-object * @return patError * @uses handlePatError() */ public function handleNotice($err) { return $this->handleError($err, E_NOTICE); } /** * handle patError Level: Warning * * @param object $err patError-object * @return patError */ public function handleWarning($err) { return $this->handleError($err, E_WARNING); } /** * handle patError Level: Error * * @param object $err patError-object * @param int $type E_ERROR (default), E_WARNING, E_NOTICE * @return patError */ public function handleError($err, $type = E_ERROR) { $log = array( 'type' => 'pat', 'msg' => $err->getMessage(), 'info' => $err->getInfo(), 'file' => $err->getFile(), 'line' => $err->getLine(), ); $backtrace = $err->getBacktrace(); $backtrace = array_slice($backtrace, 3); $useLogger = $this->checkLogger(); switch( $type ) { case E_ERROR: if( $useLogger ) { WBLog::start('error')->err( $log ); $this->logBacktrace( $backtrace ); } $this->kill(); break; case E_WARNING: if( $useLogger ) { WBLog::start('error')->warn($log); $this->logBacktrace( $backtrace ); } break; case E_NOTICE: if( $useLogger ) { WBLog::start('error')->notice($log); $this->logBacktrace( $backtrace ); } break; } return $err; } } ?>