1
1
<?php
2
+
2
3
/**
3
4
* CodeIgniter
4
5
*
26
27
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27
28
* THE SOFTWARE.
28
29
*
29
- * @package CodeIgniter
30
- * @author EllisLab Dev Team
31
- * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
32
- * @copyright Copyright (c) 2014 - 2019, British Columbia Institute of Technology (https://bcit.ca/)
33
- * @copyright Copyright (c) 2019 - 2022, CodeIgniter Foundation (https://codeigniter.com/)
34
- * @license https://opensource.org/licenses/MIT MIT License
35
- * @link https://codeigniter.com
36
- * @since Version 1.0.0
30
+ * @package CodeIgniter
31
+ * @author EllisLab Dev Team
32
+ * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
33
+ * @copyright Copyright (c) 2014 - 2019, British Columbia Institute of Technology (https://bcit.ca/)
34
+ * @copyright Copyright (c) 2019 - 2022, CodeIgniter Foundation (https://codeigniter.com/)
35
+ * @license https://opensource.org/licenses/MIT MIT License
36
+ * @link https://codeigniter.com
37
+ * @since Version 1.0.0
37
38
* @filesource
38
39
*/
39
- defined ('BASEPATH ' ) OR exit ('No direct script access allowed ' );
40
+ defined ('BASEPATH ' ) or exit ('No direct script access allowed ' );
40
41
41
42
/**
42
43
* Exceptions Class
43
44
*
44
- * @package CodeIgniter
45
- * @subpackage Libraries
46
- * @category Exceptions
47
- * @author EllisLab Dev Team
48
- * @link https://codeigniter.com/userguide3/libraries/exceptions.html
45
+ * @package CodeIgniter
46
+ * @subpackage Libraries
47
+ * @category Exceptions
48
+ * @author EllisLab Dev Team
49
+ * @link https://codeigniter.com/userguide3/libraries/exceptions.html
49
50
*/
50
- class CI_Exceptions {
51
+ class CI_Exceptions
52
+ {
51
53
52
54
/**
53
55
* Nesting level of the output buffering mechanism
54
56
*
55
- * @var int
57
+ * @var int
56
58
*/
57
59
public $ ob_level ;
58
60
59
61
/**
60
62
* List of available error levels
61
63
*
62
- * @var array
64
+ * @var array
63
65
*/
64
66
public $ levels = array (
65
- E_ERROR => 'Error ' ,
66
- E_WARNING => 'Warning ' ,
67
- E_PARSE => 'Parsing Error ' ,
68
- E_NOTICE => 'Notice ' ,
69
- E_CORE_ERROR => 'Core Error ' ,
70
- E_CORE_WARNING => 'Core Warning ' ,
71
- E_COMPILE_ERROR => 'Compile Error ' ,
72
- E_COMPILE_WARNING => 'Compile Warning ' ,
73
- E_USER_ERROR => 'User Error ' ,
74
- E_USER_WARNING => 'User Warning ' ,
75
- E_USER_NOTICE => 'User Notice ' ,
76
- E_STRICT => 'Runtime Notice '
67
+ E_ERROR => 'Error ' ,
68
+ E_WARNING => 'Warning ' ,
69
+ E_PARSE => 'Parsing Error ' ,
70
+ E_NOTICE => 'Notice ' ,
71
+ E_CORE_ERROR => 'Core Error ' ,
72
+ E_CORE_WARNING => 'Core Warning ' ,
73
+ E_COMPILE_ERROR => 'Compile Error ' ,
74
+ E_COMPILE_WARNING => 'Compile Warning ' ,
75
+ E_USER_ERROR => 'User Error ' ,
76
+ E_USER_WARNING => 'User Warning ' ,
77
+ E_USER_NOTICE => 'User Notice '
77
78
);
78
79
79
80
/**
80
81
* Class constructor
81
82
*
82
- * @return void
83
+ * @return void
83
84
*/
84
85
public function __construct ()
85
86
{
86
87
$ this ->ob_level = ob_get_level ();
87
88
// Note: Do not log messages from this constructor.
89
+
90
+ // Check if PHP version is less than 8.4.0 and E_STRICT is defined
91
+ if (version_compare (PHP_VERSION , '8.4.0 ' , '< ' ) && defined ('E_STRICT ' )) {
92
+ $ this ->levels [E_STRICT ] = 'Runtime Notice ' ;
93
+ }
88
94
}
89
95
90
96
// --------------------------------------------------------------------
@@ -94,47 +100,43 @@ public function __construct()
94
100
*
95
101
* Logs PHP generated error messages
96
102
*
97
- * @param int $severity Log level
98
- * @param string $message Error message
99
- * @param string $filepath File path
100
- * @param int $line Line number
101
- * @return void
103
+ * @param int $severity Log level
104
+ * @param string $message Error message
105
+ * @param string $filepath File path
106
+ * @param int $line Line number
107
+ * @return void
102
108
*/
103
109
#[\ReturnTypeWillChange]
104
110
public function log_exception ($ severity , $ message , $ filepath , $ line )
105
111
{
106
112
$ severity = isset ($ this ->levels [$ severity ]) ? $ this ->levels [$ severity ] : $ severity ;
107
- log_message ('error ' , 'Severity: ' . $ severity. ' --> ' . $ message. ' ' . $ filepath. ' ' . $ line );
113
+ log_message ('error ' , 'Severity: ' . $ severity . ' --> ' . $ message . ' ' . $ filepath . ' ' . $ line );
108
114
}
109
115
110
116
// --------------------------------------------------------------------
111
117
112
118
/**
113
119
* 404 Error Handler
114
120
*
115
- * @uses CI_Exceptions::show_error()
121
+ * @param string $page Page URI
122
+ * @param bool $log_error Whether to log the error
123
+ * @return void
124
+ * @uses CI_Exceptions::show_error()
116
125
*
117
- * @param string $page Page URI
118
- * @param bool $log_error Whether to log the error
119
- * @return void
120
126
*/
121
- public function show_404 ($ page = '' , $ log_error = TRUE )
127
+ public function show_404 ($ page = '' , $ log_error = true )
122
128
{
123
- if (is_cli ())
124
- {
129
+ if (is_cli ()) {
125
130
$ heading = 'Not Found ' ;
126
131
$ message = 'The controller/method pair you requested was not found. ' ;
127
- }
128
- else
129
- {
132
+ } else {
130
133
$ heading = '404 Page Not Found ' ;
131
134
$ message = 'The page you requested was not found. ' ;
132
135
}
133
136
134
137
// By default we log this, but allow a dev to skip it
135
- if ($ log_error )
136
- {
137
- log_message ('error ' , $ heading .': ' .$ page );
138
+ if ($ log_error ) {
139
+ log_message ('error ' , $ heading . ': ' . $ page );
138
140
}
139
141
140
142
echo $ this ->show_error ($ heading , $ message , 'error_404 ' , 404 );
@@ -149,50 +151,41 @@ public function show_404($page = '', $log_error = TRUE)
149
151
* Takes an error message as input (either as a string or an array)
150
152
* and displays it using the specified template.
151
153
*
152
- * @param string $heading Page heading
153
- * @param string|string[] $message Error message
154
- * @param string $template Template name
155
- * @param int $status_code (default: 500)
154
+ * @param string $heading Page heading
155
+ * @param string|string[] $message Error message
156
+ * @param string $template Template name
157
+ * @param int $status_code (default: 500)
156
158
*
157
- * @return string Error page output
159
+ * @return string Error page output
158
160
*/
159
161
public function show_error ($ heading , $ message , $ template = 'error_general ' , $ status_code = 500 )
160
162
{
161
163
$ templates_path = config_item ('error_views_path ' );
162
- if (empty ($ templates_path ))
163
- {
164
- $ templates_path = VIEWPATH .'errors ' .DIRECTORY_SEPARATOR ;
164
+ if (empty ($ templates_path )) {
165
+ $ templates_path = VIEWPATH . 'errors ' . DIRECTORY_SEPARATOR ;
165
166
}
166
167
167
- if (is_cli ())
168
- {
169
- $ message = "\t" .(is_array ($ message ) ? implode ("\n\t" , $ message ) : $ message );
170
- $ template = 'cli ' .DIRECTORY_SEPARATOR .$ template ;
171
- }
172
- else
173
- {
168
+ if (is_cli ()) {
169
+ $ message = "\t" . (is_array ($ message ) ? implode ("\n\t" , $ message ) : $ message );
170
+ $ template = 'cli ' . DIRECTORY_SEPARATOR . $ template ;
171
+ } else {
174
172
set_status_header ($ status_code );
175
- if (is_array ($ message ))
176
- {
177
- foreach ($ message as &$ value )
178
- {
173
+ if (is_array ($ message )) {
174
+ foreach ($ message as &$ value ) {
179
175
$ value = htmlspecialchars ($ value );
180
176
}
181
- }
182
- else
183
- {
177
+ } else {
184
178
$ message = htmlspecialchars ($ message );
185
179
}
186
- $ message = '<p> ' . (is_array ($ message ) ? implode ('</p><p> ' , $ message ) : $ message ). '</p> ' ;
187
- $ template = 'html ' . DIRECTORY_SEPARATOR . $ template ;
180
+ $ message = '<p> ' . (is_array ($ message ) ? implode ('</p><p> ' , $ message ) : $ message ) . '</p> ' ;
181
+ $ template = 'html ' . DIRECTORY_SEPARATOR . $ template ;
188
182
}
189
183
190
- if (ob_get_level () > $ this ->ob_level + 1 )
191
- {
184
+ if (ob_get_level () > $ this ->ob_level + 1 ) {
192
185
ob_end_flush ();
193
186
}
194
187
ob_start ();
195
- include ($ templates_path. $ template. '.php ' );
188
+ include ($ templates_path . $ template . '.php ' );
196
189
$ buffer = ob_get_contents ();
197
190
ob_end_clean ();
198
191
return $ buffer ;
@@ -203,33 +196,27 @@ public function show_error($heading, $message, $template = 'error_general', $sta
203
196
public function show_exception ($ exception )
204
197
{
205
198
$ templates_path = config_item ('error_views_path ' );
206
- if (empty ($ templates_path ))
207
- {
208
- $ templates_path = VIEWPATH .'errors ' .DIRECTORY_SEPARATOR ;
199
+ if (empty ($ templates_path )) {
200
+ $ templates_path = VIEWPATH . 'errors ' . DIRECTORY_SEPARATOR ;
209
201
}
210
202
211
203
$ message = $ exception ->getMessage ();
212
- if (empty ($ message ))
213
- {
204
+ if (empty ($ message )) {
214
205
$ message = '(null) ' ;
215
206
}
216
207
217
- if (is_cli ())
218
- {
219
- $ templates_path .= 'cli ' .DIRECTORY_SEPARATOR ;
220
- }
221
- else
222
- {
223
- $ templates_path .= 'html ' .DIRECTORY_SEPARATOR ;
208
+ if (is_cli ()) {
209
+ $ templates_path .= 'cli ' . DIRECTORY_SEPARATOR ;
210
+ } else {
211
+ $ templates_path .= 'html ' . DIRECTORY_SEPARATOR ;
224
212
}
225
213
226
- if (ob_get_level () > $ this ->ob_level + 1 )
227
- {
214
+ if (ob_get_level () > $ this ->ob_level + 1 ) {
228
215
ob_end_flush ();
229
216
}
230
217
231
218
ob_start ();
232
- include ($ templates_path. 'error_exception.php ' );
219
+ include ($ templates_path . 'error_exception.php ' );
233
220
$ buffer = ob_get_contents ();
234
221
ob_end_clean ();
235
222
echo $ buffer ;
@@ -240,45 +227,39 @@ public function show_exception($exception)
240
227
/**
241
228
* Native PHP error handler
242
229
*
243
- * @param int $severity Error level
244
- * @param string $message Error message
245
- * @param string $filepath File path
246
- * @param int $line Line number
247
- * @return void
230
+ * @param int $severity Error level
231
+ * @param string $message Error message
232
+ * @param string $filepath File path
233
+ * @param int $line Line number
234
+ * @return void
248
235
*/
249
236
public function show_php_error ($ severity , $ message , $ filepath , $ line )
250
237
{
251
238
$ templates_path = config_item ('error_views_path ' );
252
- if (empty ($ templates_path ))
253
- {
254
- $ templates_path = VIEWPATH .'errors ' .DIRECTORY_SEPARATOR ;
239
+ if (empty ($ templates_path )) {
240
+ $ templates_path = VIEWPATH . 'errors ' . DIRECTORY_SEPARATOR ;
255
241
}
256
242
257
243
$ severity = isset ($ this ->levels [$ severity ]) ? $ this ->levels [$ severity ] : $ severity ;
258
244
259
245
// For safety reasons we don't show the full file path in non-CLI requests
260
- if ( ! is_cli ())
261
- {
246
+ if (!is_cli ()) {
262
247
$ filepath = str_replace ('\\' , '/ ' , $ filepath );
263
- if (FALSE !== strpos ($ filepath , '/ ' ))
264
- {
248
+ if (false !== strpos ($ filepath , '/ ' )) {
265
249
$ x = explode ('/ ' , $ filepath );
266
- $ filepath = $ x [count ($ x )- 2 ]. '/ ' . end ($ x );
250
+ $ filepath = $ x [count ($ x ) - 2 ] . '/ ' . end ($ x );
267
251
}
268
252
269
- $ template = 'html ' .DIRECTORY_SEPARATOR .'error_php ' ;
270
- }
271
- else
272
- {
273
- $ template = 'cli ' .DIRECTORY_SEPARATOR .'error_php ' ;
253
+ $ template = 'html ' . DIRECTORY_SEPARATOR . 'error_php ' ;
254
+ } else {
255
+ $ template = 'cli ' . DIRECTORY_SEPARATOR . 'error_php ' ;
274
256
}
275
257
276
- if (ob_get_level () > $ this ->ob_level + 1 )
277
- {
258
+ if (ob_get_level () > $ this ->ob_level + 1 ) {
278
259
ob_end_flush ();
279
260
}
280
261
ob_start ();
281
- include ($ templates_path. $ template. '.php ' );
262
+ include ($ templates_path . $ template . '.php ' );
282
263
$ buffer = ob_get_contents ();
283
264
ob_end_clean ();
284
265
echo $ buffer ;
0 commit comments