blob: 4bdbe4f83be3634bf5b5d69fe076b24f57d83328 [file] [log] [blame]
adminb0dd10f2006-08-25 17:25:49 +00001<?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.
10 * @license http://www.codeignitor.com/user_guide/license.html
11 * @link http://www.codeigniter.com
12 * @since Version 1.0
13 * @filesource
14 */
15
16// ------------------------------------------------------------------------
17
18/**
19 * Exceptions Class
20 *
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 */
27class 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 /**
51 * Constructor
52 *
53 */
54 function CI_Exceptions()
55 {
adminbc042dd2006-09-21 02:46:59 +000056 // Note: Do not log messages from this constructor.
adminb0dd10f2006-08-25 17:25:49 +000057 }
58 // END CI_Exceptions()
59
60 // --------------------------------------------------------------------
61
62 /**
63 * Exception Logger
64 *
65 * This function logs PHP generated error messages
66 *
67 * @access private
68 * @param string the error severity
69 * @param string the error string
70 * @param string the error filepath
71 * @param string the error line number
72 * @return string
73 */
74 function log_exception($severity, $message, $filepath, $line)
75 {
76 $severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity];
77
78 log_message('error', 'Severity: '.$severity.' '.$severity.' --> '.$message. ' '.$filepath.' '.$line, TRUE);
79 }
80 // END log_exception()
81
82 // --------------------------------------------------------------------
83
84 /**
85 * 404 Page Not Found Handler
86 *
87 * @access private
88 * @param string
89 * @return string
90 */
91 function show_404($page = '')
92 {
93 $heading = "404 Page Not Found";
94 $message = "The page you requested was not found.";
95
96 log_message('error', '404 Page Not Found --> '.$page);
97 echo $this->show_error($heading, $message, 'error_404');
98 exit;
99 }
100 // END show_404()
101
102 // --------------------------------------------------------------------
103
104 /**
105 * General Error Page
106 *
107 * This function takes an error message as input
108 * (either as a string or an array) and displayes
109 * it using the specified template.
110 *
111 * @access private
112 * @param string the heading
113 * @param string the message
114 * @param string the template name
115 * @return string
116 */
117 function show_error($heading, $message, $template = 'error_general')
118 {
119 $message = '<p>'.implode('</p><p>', ( ! is_array($message)) ? array($message) : $message).'</p>';
admine0cd6092006-10-20 01:00:31 +0000120
121 if (ob_get_level() > 1)
122 {
123 ob_end_flush();
124 }
adminb0dd10f2006-08-25 17:25:49 +0000125 ob_start();
126 include_once(APPPATH.'errors/'.$template.EXT);
127 $buffer = ob_get_contents();
128 ob_end_clean();
129 return $buffer;
130 }
131 // END show_error()
132
133
134 // --------------------------------------------------------------------
135
136 /**
137 * Native PHP error handler
138 *
139 * @access private
140 * @param string the error severity
141 * @param string the error string
142 * @param string the error filepath
143 * @param string the error line number
144 * @return string
145 */
146 function show_php_error($severity, $message, $filepath, $line)
147 {
148 $severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity];
149
150 $filepath = str_replace("\\", "/", $filepath);
151
152 // For safety reasons we do not show the full file path
153 if (FALSE !== strpos($filepath, '/'))
154 {
155 $x = explode('/', $filepath);
156 $filepath = $x[count($x)-2].'/'.end($x);
157 }
admine0cd6092006-10-20 01:00:31 +0000158
159 if (ob_get_level() > 1)
160 {
161 ob_end_flush();
162 }
adminb0dd10f2006-08-25 17:25:49 +0000163 ob_start();
164 include_once(APPPATH.'errors/error_php'.EXT);
165 $buffer = ob_get_contents();
166 ob_end_clean();
167 echo $buffer;
168 }
169 // END show_php_error()
170
171// END Exceptions Class
172}
173?>