* @link http://netmonsters.ru * @package Majestic * @subpackage exception * @since 2010-02-26 */ class ErrorHandler { static public function init() { set_error_handler(array('ErrorHandler', 'error_handler')); } static public function error_handler($errno, $errstr, $errfile, $errline) { $ob_handlers = ob_get_status(); if (!empty($ob_handlers)) { ob_end_clean(); } if (error_reporting() !== 0) { throw new ErrorException($errstr, 0, $errno, $errfile, $errline); } return true; } static protected function getSource($file, $hiline) { $code = array(); $i = 0; foreach (file($file) as $line) { $i++; if ($i >= $hiline - 10 && $i <= $hiline + 10) { if ($i == $hiline) { $code[] = '' . $i . '' . htmlentities($line, ENT_QUOTES, 'UTF-8') . ''; } else { $code[] = '' . $i . '' . htmlentities($line, ENT_QUOTES, 'UTF-8') . ''; } } if ($i > $hiline + 10) { break; } } return implode('', $code); } static protected function wrapArray($array, $name) { if (!$array) { return '

No ' . $name . ' data

'; } $text = ''; foreach ($array as $key => $value) { if (is_array($value) || is_object($value)) { $value = print_r($value, true); } $value = ($value) ? htmlentities($value, ENT_QUOTES, 'UTF-8') : ' '; $text .= ''; } $text .= '
VariableValue
' . $key . '
' . $value . '
'; return $text; } static protected function wrapTrace($trace) { return '' . nl2br($trace) . ''; } /** * @param Exception $exception * @return string */ static public function showDebug($exception) { $ob_handlers = ob_get_status(); if (!empty($ob_handlers)) { ob_end_clean(); } $class = get_class($exception); $method = Env::Server('REQUEST_METHOD', ''); $uri = Env::getRequestUri(); $source = self::getSource($exception->getFile(), $exception->getLine()); $time = date('r', Env::Server('REQUEST_TIME', time())); $trace = nl2br($exception->getTraceAsString()); $get = self::wrapArray(Env::Get(), 'GET'); $post = self::wrapArray(Env::Post(), 'POST'); $session = self::wrapArray(Session::get(), 'SESSION'); $files = self::wrapArray(Env::Files(), 'FILES'); $cookies = self::wrapArray(Env::Cookie(), 'COOKIE'); $server = self::wrapArray(Env::Server(), 'SERVER'); $message = << {$class} at {$uri}

{$class} at {$uri}

{$exception->getMessage()}
Request Method:{$method}
Exception Type:{$class}
Exception Message:
{$exception->getMessage()}
Exception Location:{$exception->getFile()}, line {$exception->getLine()}
Server time:{$time}

Context

In file {$exception->getFile()}, error at line {$exception->getLine()}

{$exception->getMessage()}

{$source}

Traceback

{$trace}

Request information

GET

{$get}

POST

{$post}

SESSION

{$session}

FILES

{$files} {$cookies}

SERVER

{$server}

Settings

todo

You're seeing this error because you have defined constant DEBUG = True in your config file. Change that to False, and it will display a standard 500 page.

EOD; return $message; } }