| 1 |
joko |
1.1 |
<? |
| 2 |
|
|
// ------------------------------------------------------------------------- |
| 3 |
joko |
1.4 |
// $Id: ErrorHandler.php,v 1.3 2002/12/13 09:19:32 joko Exp $ |
| 4 |
joko |
1.1 |
// ------------------------------------------------------------------------- |
| 5 |
joko |
1.2 |
// $Log: ErrorHandler.php,v $ |
| 6 |
joko |
1.4 |
// Revision 1.3 2002/12/13 09:19:32 joko |
| 7 |
|
|
// + debugging |
| 8 |
|
|
// |
| 9 |
joko |
1.3 |
// Revision 1.2 2002/12/01 04:47:19 joko |
| 10 |
|
|
// + comments |
| 11 |
|
|
// |
| 12 |
joko |
1.2 |
// Revision 1.1 2002/11/12 05:42:30 joko |
| 13 |
|
|
// + initial checkin |
| 14 |
|
|
// |
| 15 |
joko |
1.1 |
// ------------------------------------------------------------------------- |
| 16 |
|
|
|
| 17 |
joko |
1.2 |
|
| 18 |
|
|
// TODO: maybe use and/or enhance ErrorHandler from http://phpclasses.php-start.de/browse.html/package/345.html |
| 19 |
joko |
1.1 |
|
| 20 |
|
|
function error_handler($level, $message, $file, $line, $context) { |
| 21 |
|
|
global $Application_Error; |
| 22 |
|
|
$Application_Error['this']->callErrorHandler($level, $message, $file, $line, $context); |
| 23 |
|
|
} |
| 24 |
|
|
|
| 25 |
|
|
class Application_ErrorHandler { |
| 26 |
|
|
|
| 27 |
|
|
function Application_ErrorHandler(&$debugbox) { |
| 28 |
|
|
$this->QUIET = 1; |
| 29 |
|
|
$this->debugbox = $debugbox; |
| 30 |
|
|
} |
| 31 |
|
|
|
| 32 |
|
|
function activate($level = E_ALL) { |
| 33 |
|
|
//return; |
| 34 |
joko |
1.3 |
//print "1<br>"; |
| 35 |
|
|
//exit; |
| 36 |
joko |
1.1 |
global $Application_Error; |
| 37 |
joko |
1.3 |
//print "2<br>"; |
| 38 |
joko |
1.1 |
$Application_Error[this] = $this; |
| 39 |
joko |
1.3 |
//print "3<br>"; |
| 40 |
joko |
1.1 |
//error_reporting($level); |
| 41 |
|
|
error_reporting(E_ALL); |
| 42 |
joko |
1.3 |
//print "4<br>"; |
| 43 |
joko |
1.1 |
set_error_handler('error_handler'); |
| 44 |
joko |
1.3 |
//print "5<br>"; |
| 45 |
joko |
1.1 |
} |
| 46 |
|
|
|
| 47 |
|
|
function callErrorHandler($level, $message, $file, $line, $context) { |
| 48 |
|
|
|
| 49 |
|
|
$phperror_type = array ( |
| 50 |
|
|
1 => "Error", |
| 51 |
|
|
2 => "Warning", |
| 52 |
|
|
4 => "Parsing Error", |
| 53 |
|
|
8 => "Notice", |
| 54 |
|
|
16 => "Core Error", |
| 55 |
|
|
32 => "Core Warning", |
| 56 |
|
|
64 => "Compile Error", |
| 57 |
|
|
128 => "Compile Warning", |
| 58 |
|
|
256 => "User Error", |
| 59 |
|
|
512 => "User Warning", |
| 60 |
|
|
1024=> "User Notice" |
| 61 |
|
|
); |
| 62 |
|
|
|
| 63 |
|
|
$level_text = $phperror_type[$level]; |
| 64 |
|
|
|
| 65 |
|
|
if ($level == E_USER_NOTICE) { |
| 66 |
|
|
$phperror = $message; |
| 67 |
|
|
} else { |
| 68 |
|
|
|
| 69 |
|
|
$phperror = " |
| 70 |
|
|
PHP-Error: |
| 71 |
|
|
level: $level ($level_text) |
| 72 |
|
|
file: $file |
| 73 |
|
|
line: $line |
| 74 |
|
|
The error message was: $message |
| 75 |
|
|
"; |
| 76 |
|
|
} |
| 77 |
|
|
|
| 78 |
|
|
//The following variables were set in the scope that the error occurred in: |
| 79 |
|
|
//" . dumpVar($context); |
| 80 |
|
|
|
| 81 |
|
|
if ($this->debugbox) { |
| 82 |
|
|
$this->debugbox->append($phperror, $level); |
| 83 |
|
|
} |
| 84 |
|
|
|
| 85 |
|
|
if (isset($this->site)) { |
| 86 |
|
|
|
| 87 |
|
|
// logging mechanism |
| 88 |
joko |
1.4 |
$this->site->log($phperror, PEAR_LOG_ERR); |
| 89 |
joko |
1.1 |
|
| 90 |
|
|
// redirection to "STDOUT", make html for output |
| 91 |
|
|
if ($this->site->config['mode']['PHPERRORS_LEVEL']) { |
| 92 |
|
|
if ($level <= $this->site->config['mode']['PHPERRORS_LEVEL']) { |
| 93 |
|
|
$phperror = str_replace("\n", "<br>", $phperror); |
| 94 |
|
|
print $phperror; |
| 95 |
|
|
} |
| 96 |
|
|
} |
| 97 |
|
|
|
| 98 |
|
|
} elseif (!$this->QUIET) { |
| 99 |
|
|
$phperror = str_replace("\n", "<br>", $phperror); |
| 100 |
|
|
print $phperror; |
| 101 |
|
|
} |
| 102 |
|
|
|
| 103 |
|
|
if ($level < E_ERROR) { |
| 104 |
|
|
// TODO: logfile? |
| 105 |
|
|
print $message . "<br>"; |
| 106 |
|
|
} |
| 107 |
|
|
|
| 108 |
|
|
//print_r ($context); |
| 109 |
|
|
//print "\n</blockquote>"; |
| 110 |
|
|
} |
| 111 |
|
|
|
| 112 |
|
|
} |
| 113 |
|
|
|
| 114 |
|
|
?> |