admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 1 | <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); |
| 2 | /** |
| 3 | * Code Igniter |
| 4 | * |
| 5 | * An open source application development framework for PHP 4.3.2 or newer |
| 6 | * |
| 7 | * @package CodeIgniter |
| 8 | * @author Rick Ellis |
| 9 | * @copyright Copyright (c) 2006, pMachine, Inc. |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 10 | * @license http://www.codeignitor.com/user_guide/license.html |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 11 | * @link http://www.codeigniter.com |
| 12 | * @since Version 1.0 |
| 13 | * @filesource |
| 14 | */ |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 15 | |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 16 | // ------------------------------------------------------------------------ |
| 17 | |
| 18 | /** |
| 19 | * Exceptions Class |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 20 | * |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 21 | * @package CodeIgniter |
| 22 | * @subpackage Libraries |
| 23 | * @category Exceptions |
| 24 | * @author Rick Ellis |
| 25 | * @link http://www.codeigniter.com/user_guide/libraries/exceptions.html |
| 26 | */ |
| 27 | class CI_Exceptions { |
| 28 | var $action; |
| 29 | var $severity; |
| 30 | var $message; |
| 31 | var $filename; |
| 32 | var $line; |
| 33 | |
| 34 | var $levels = array( |
| 35 | E_ERROR => 'Error', |
| 36 | E_WARNING => 'Warning', |
| 37 | E_PARSE => 'Parsing Error', |
| 38 | E_NOTICE => 'Notice', |
| 39 | E_CORE_ERROR => 'Core Error', |
| 40 | E_CORE_WARNING => 'Core Warning', |
| 41 | E_COMPILE_ERROR => 'Compile Error', |
| 42 | E_COMPILE_WARNING => 'Compile Warning', |
| 43 | E_USER_ERROR => 'User Error', |
| 44 | E_USER_WARNING => 'User Warning', |
| 45 | E_USER_NOTICE => 'User Notice', |
| 46 | E_STRICT => 'Runtime Notice' |
| 47 | ); |
| 48 | |
| 49 | |
| 50 | /** |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 51 | * Constructor |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 52 | * |
| 53 | */ |
| 54 | function CI_Exceptions() |
| 55 | { |
admin | bc042dd | 2006-09-21 02:46:59 +0000 | [diff] [blame] | 56 | // Note: Do not log messages from this constructor. |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 57 | } |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 58 | |
| 59 | // -------------------------------------------------------------------- |
| 60 | |
| 61 | /** |
| 62 | * Exception Logger |
| 63 | * |
| 64 | * This function logs PHP generated error messages |
| 65 | * |
| 66 | * @access private |
| 67 | * @param string the error severity |
| 68 | * @param string the error string |
| 69 | * @param string the error filepath |
| 70 | * @param string the error line number |
| 71 | * @return string |
| 72 | */ |
| 73 | function log_exception($severity, $message, $filepath, $line) |
| 74 | { |
| 75 | $severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity]; |
| 76 | |
| 77 | log_message('error', 'Severity: '.$severity.' '.$severity.' --> '.$message. ' '.$filepath.' '.$line, TRUE); |
| 78 | } |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 79 | |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 80 | // -------------------------------------------------------------------- |
| 81 | |
| 82 | /** |
| 83 | * 404 Page Not Found Handler |
| 84 | * |
| 85 | * @access private |
| 86 | * @param string |
| 87 | * @return string |
| 88 | */ |
| 89 | function show_404($page = '') |
| 90 | { |
| 91 | $heading = "404 Page Not Found"; |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 92 | $message = "The page you requested was not found."; |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 93 | |
| 94 | log_message('error', '404 Page Not Found --> '.$page); |
| 95 | echo $this->show_error($heading, $message, 'error_404'); |
| 96 | exit; |
| 97 | } |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 98 | |
| 99 | // -------------------------------------------------------------------- |
| 100 | |
| 101 | /** |
| 102 | * General Error Page |
| 103 | * |
| 104 | * This function takes an error message as input |
admin | bd6bee7 | 2006-10-21 19:39:00 +0000 | [diff] [blame] | 105 | * (either as a string or an array) and displays |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 106 | * it using the specified template. |
| 107 | * |
| 108 | * @access private |
| 109 | * @param string the heading |
| 110 | * @param string the message |
| 111 | * @param string the template name |
| 112 | * @return string |
| 113 | */ |
| 114 | function show_error($heading, $message, $template = 'error_general') |
| 115 | { |
| 116 | $message = '<p>'.implode('</p><p>', ( ! is_array($message)) ? array($message) : $message).'</p>'; |
admin | e0cd609 | 2006-10-20 01:00:31 +0000 | [diff] [blame] | 117 | |
| 118 | if (ob_get_level() > 1) |
| 119 | { |
| 120 | ob_end_flush(); |
| 121 | } |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 122 | ob_start(); |
| 123 | include_once(APPPATH.'errors/'.$template.EXT); |
| 124 | $buffer = ob_get_contents(); |
| 125 | ob_end_clean(); |
| 126 | return $buffer; |
| 127 | } |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 128 | |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 129 | // -------------------------------------------------------------------- |
| 130 | |
| 131 | /** |
| 132 | * Native PHP error handler |
| 133 | * |
| 134 | * @access private |
| 135 | * @param string the error severity |
| 136 | * @param string the error string |
| 137 | * @param string the error filepath |
| 138 | * @param string the error line number |
| 139 | * @return string |
| 140 | */ |
| 141 | function show_php_error($severity, $message, $filepath, $line) |
| 142 | { |
| 143 | $severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity]; |
| 144 | |
| 145 | $filepath = str_replace("\\", "/", $filepath); |
| 146 | |
| 147 | // For safety reasons we do not show the full file path |
| 148 | if (FALSE !== strpos($filepath, '/')) |
| 149 | { |
| 150 | $x = explode('/', $filepath); |
| 151 | $filepath = $x[count($x)-2].'/'.end($x); |
| 152 | } |
admin | e0cd609 | 2006-10-20 01:00:31 +0000 | [diff] [blame] | 153 | |
| 154 | if (ob_get_level() > 1) |
| 155 | { |
| 156 | ob_end_flush(); |
| 157 | } |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 158 | ob_start(); |
| 159 | include_once(APPPATH.'errors/error_php'.EXT); |
| 160 | $buffer = ob_get_contents(); |
| 161 | ob_end_clean(); |
| 162 | echo $buffer; |
| 163 | } |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 164 | |
admin | bd6bee7 | 2006-10-21 19:39:00 +0000 | [diff] [blame] | 165 | |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 166 | } |
admin | bd6bee7 | 2006-10-21 19:39:00 +0000 | [diff] [blame] | 167 | // END Exceptions Class |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 168 | ?> |