forked from simplesamlphp/simplesamlphp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathErrorHandler.php
More file actions
72 lines (63 loc) · 1.92 KB
/
ErrorHandler.php
File metadata and controls
72 lines (63 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
declare(strict_types=1);
namespace SimpleSAML\Error;
use SimpleSAML\Logger;
use function is_null;
/**
* SimpleSAMLphp's custom error handler that logs full backtraces on errors and warnings
*
* @package SimpleSAMLphp
*/
class ErrorHandler
{
/**
* @param int $errno
* @param string $errstr
* @param string|null $errfile
* @param int $errline
* @param string|null $errcontext
* @return false
* @throws \Exception
*/
public function customErrorHandler(
int $errno,
string $errstr,
?string $errfile = null,
int $errline = 0,
): false {
if (Logger::isErrorMasked($errno)) {
// masked error
return false;
}
static $limit = 5;
$limit -= 1;
if ($limit < 0) {
// we have reached the limit in the number of backtraces we will log
return false;
}
$levels = [
E_DEPRECATED => 'Deprecated',
E_USER_DEPRECATED => 'User Deprecated',
E_NOTICE => 'Notice',
E_USER_NOTICE => 'User Notice',
// E_STRICT (2048) has become deprecated in PHP 8.4
2048 => 'Runtime Notice',
E_WARNING => 'Warning',
E_USER_WARNING => 'User Warning',
E_COMPILE_WARNING => 'Compile Warning',
E_CORE_WARNING => 'Core Warning',
E_USER_ERROR => 'User Error',
E_RECOVERABLE_ERROR => 'Catchable Fatal Error',
E_COMPILE_ERROR => 'Compile Error',
E_PARSE => 'Parse Error',
E_ERROR => 'Error',
E_CORE_ERROR => 'Core Error',
];
// show an error with a full backtrace
$context = (is_null($errfile) ? '' : " at $errfile:$errline");
$e = new Exception($levels[$errno] . ' - ' . $errstr . $context);
$e->logError();
// resume normal error processing
return false;
}
}