blob: c3af801ae0fec8ed2c8bf7bfa156592388a88b4a [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>';
120
121 ob_start();
122 include_once(APPPATH.'errors/'.$template.EXT);
123 $buffer = ob_get_contents();
124 ob_end_clean();
125 return $buffer;
126 }
127 // END show_error()
128
129
130 // --------------------------------------------------------------------
131
132 /**
133 * Native PHP error handler
134 *
135 * @access private
136 * @param string the error severity
137 * @param string the error string
138 * @param string the error filepath
139 * @param string the error line number
140 * @return string
141 */
142 function show_php_error($severity, $message, $filepath, $line)
143 {
144 $severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity];
145
146 $filepath = str_replace("\\", "/", $filepath);
147
148 // For safety reasons we do not show the full file path
149 if (FALSE !== strpos($filepath, '/'))
150 {
151 $x = explode('/', $filepath);
152 $filepath = $x[count($x)-2].'/'.end($x);
153 }
154
155 ob_start();
156 include_once(APPPATH.'errors/error_php'.EXT);
157 $buffer = ob_get_contents();
158 ob_end_clean();
159 echo $buffer;
160 }
161 // END show_php_error()
162
163// END Exceptions Class
164}
165?>