PageRenderTime 18ms CodeModel.GetById 3ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/framework/boot/error/WebErrorHandler.php

http://zoop.googlecode.com/
PHP | 106 lines | 88 code | 11 blank | 7 comment | 3 complexity | e91e35697fc3679455e34ae1ef93000a MD5 | raw file
  1<?php
  2class WebErrorHandler
  3{
  4	static function throwException($errno, $errstr, $errfile, $errline, $context, $backtrace = NULL)
  5	{
  6		// maybe we should use this here: http://us3.php.net/manual/en/class.errorexception.php
  7		$e = new Exception($errstr, $errno);
  8		// echo_r($e);
  9		// die();
 10		// $e->setFile($errfile);
 11		// $e->setLine($errline);
 12		throw $e;
 13	}
 14	
 15	static function handleError($errno, $errstr, $errfile, $errline, $context, $backtrace = NULL)
 16	{
 17		if(!defined('app_status'))
 18			define('app_status', 'dev');
 19		
 20		if((error_reporting() & $errno) !== $errno)
 21			return true;
 22			
 23		switch(app_status)
 24		{
 25			case 'dev':
 26				self::handleDevError($errno, $errstr, $errfile, $errline, $context, $backtrace);
 27				break;
 28			
 29			case 'test':
 30				trigger_error('status not handled:' . app_status);
 31				break;
 32			
 33			case 'live':
 34				trigger_error('status not handled:' . app_status);
 35				break;
 36			
 37			default:
 38				trigger_error('status not handled:' . app_status);
 39				break;
 40		}
 41	}
 42	
 43	function handleDevError($errno, $errstr, $errfile, $errline, $context, $backtrace)
 44	{
 45		$errorLine = self::formatErrorLineHtml($errno, $errstr, $errfile, $errline, $context, $backtrace);
 46		echo '<p>' . $errorLine . '</p>';
 47		$backtrace = $backtrace ? $backtrace : debug_backtrace();
 48		// array_shift($backtrace);
 49		FormatBacktraceHtml($backtrace);
 50	}
 51	
 52	function formatErrorLineHtml($errno, $errstr, $errfile, $errline, $context)
 53	{
 54		$line = '';
 55		switch ($errno)
 56		{
 57			case E_ERROR:
 58			case E_PARSE:
 59			case E_CORE_ERROR:
 60			case E_COMPILE_ERROR:
 61				die('this should never happen');
 62				break;
 63			case E_CORE_WARNING:
 64			case E_COMPILE_WARNING:
 65			case E_STRICT:
 66//			case E_RECOVERABLE_ERROR:
 67				$line .= '<strong>Error type not yet handled: ' . $errno . '</strong>';
 68				break;
 69			case E_WARNING:
 70				$line .= '<strong>Warning:</strong>';
 71				break;
 72			case E_NOTICE:
 73				$line .= '<strong>Notice:</strong>';
 74				break;
 75			case E_USER_NOTICE:
 76				$line .= '<strong>User Notice:</strong>';
 77				break;
 78			case E_DEPRECATED:
 79				$line .= '<strong>Depricated:</strong>';
 80				break;
 81			case E_USER_ERROR:
 82				$line .= '<strong>User Error:</strong>';
 83				break;
 84			case E_USER_WARNING:
 85				$line .= '<strong>User Warning:</strong>';
 86				break;
 87			case 0:
 88				$line .= '<strong>Exception:</strong>';
 89				break;
 90			default:
 91				$line .= '<strong>Undefined error type: ' . $errno . '</strong>';
 92			break;
 93		}
 94		
 95		$line .= ' "' . $errstr . '"';
 96		$line .= ' in file ' . $errfile;
 97		$line .= ' ( on line  ' . $errline . ')';
 98		
 99		return $line;
100	}
101	
102	function exceptionHandler($exception)
103	{
104		self::handleError($exception->getCode(), $exception->getMessage(), $exception->getFile(), $exception->getLine(), NULL, $exception->getTrace());
105	}
106}