blob: 6d58ee6b9281c93d565a2ac8f3412b35d3cc6a9e [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.
admine334c472006-10-21 19:44:22 +000010 * @license http://www.codeignitor.com/user_guide/license.html
adminb0dd10f2006-08-25 17:25:49 +000011 * @link http://www.codeigniter.com
12 * @since Version 1.0
13 * @filesource
14 */
admine334c472006-10-21 19:44:22 +000015
adminb0dd10f2006-08-25 17:25:49 +000016// ------------------------------------------------------------------------
17
18/**
19 * Exceptions Class
admine334c472006-10-21 19:44:22 +000020 *
adminb0dd10f2006-08-25 17:25:49 +000021 * @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 /**
admine334c472006-10-21 19:44:22 +000051 * Constructor
adminb0dd10f2006-08-25 17:25:49 +000052 *
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 }
adminb0dd10f2006-08-25 17:25:49 +000058
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 }
admine334c472006-10-21 19:44:22 +000079
adminb0dd10f2006-08-25 17:25:49 +000080 // --------------------------------------------------------------------
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";
admine334c472006-10-21 19:44:22 +000092 $message = "The page you requested was not found.";
adminb0dd10f2006-08-25 17:25:49 +000093
94 log_message('error', '404 Page Not Found --> '.$page);
95 echo $this->show_error($heading, $message, 'error_404');
96 exit;
97 }
adminb0dd10f2006-08-25 17:25:49 +000098
99 // --------------------------------------------------------------------
100
101 /**
102 * General Error Page
103 *
104 * This function takes an error message as input
adminbd6bee72006-10-21 19:39:00 +0000105 * (either as a string or an array) and displays
adminb0dd10f2006-08-25 17:25:49 +0000106 * 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>';
admine0cd6092006-10-20 01:00:31 +0000117
118 if (ob_get_level() > 1)
119 {
120 ob_end_flush();
121 }
adminb0dd10f2006-08-25 17:25:49 +0000122 ob_start();
123 include_once(APPPATH.'errors/'.$template.EXT);
124 $buffer = ob_get_contents();
125 ob_end_clean();
126 return $buffer;
127 }
admine334c472006-10-21 19:44:22 +0000128
adminb0dd10f2006-08-25 17:25:49 +0000129 // --------------------------------------------------------------------
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 }
admine0cd6092006-10-20 01:00:31 +0000153
154 if (ob_get_level() > 1)
155 {
156 ob_end_flush();
157 }
adminb0dd10f2006-08-25 17:25:49 +0000158 ob_start();
159 include_once(APPPATH.'errors/error_php'.EXT);
160 $buffer = ob_get_contents();
161 ob_end_clean();
162 echo $buffer;
163 }
adminb0dd10f2006-08-25 17:25:49 +0000164
adminbd6bee72006-10-21 19:39:00 +0000165
adminb0dd10f2006-08-25 17:25:49 +0000166}
adminbd6bee72006-10-21 19:39:00 +0000167// END Exceptions Class
adminb0dd10f2006-08-25 17:25:49 +0000168?>