|
9 | 9 | use SimpleSAML\Compat\SspContainer; |
10 | 10 | use SimpleSAML\Configuration; |
11 | 11 | use SimpleSAML\Error; |
12 | | -use SimpleSAML\Logger; |
13 | | -use SimpleSAML\Module; |
14 | 12 | use SimpleSAML\Utils; |
15 | 13 |
|
16 | | -/** |
17 | | - * show error page on unhandled exceptions |
18 | | - * @param \Throwable $exception |
19 | | - * @return void |
20 | | - */ |
21 | | -function SimpleSAML_exception_handler(Throwable $exception): void |
22 | | -{ |
23 | | - Module::callHooks('exception_handler', $exception); |
| 14 | +$exceptionHandler = new Error\ExceptionHandler(); |
| 15 | +set_exception_handler([$exceptionHandler, 'customExceptionHandler']); |
24 | 16 |
|
25 | | - if ($exception instanceof Error\Error) { |
26 | | - $exception->show(); |
27 | | - } elseif ($exception instanceof Exception) { |
28 | | - $e = new Error\Error('UNHANDLEDEXCEPTION', $exception); |
29 | | - $e->show(); |
30 | | - } elseif (class_exists('Error') && $exception instanceof \Error) { |
31 | | - $e = new Error\Error('UNHANDLEDEXCEPTION', $exception); |
32 | | - $e->show(); |
33 | | - } |
34 | | -} |
35 | | - |
36 | | -set_exception_handler('SimpleSAML_exception_handler'); |
37 | | - |
38 | | -// log full backtrace on errors and warnings |
39 | | -/** |
40 | | - * @param int $errno |
41 | | - * @param string $errstr |
42 | | - * @param string|null $errfile |
43 | | - * @param int $errline |
44 | | - * @param string|null $errcontext |
45 | | - * @return false |
46 | | - */ |
47 | | -function SimpleSAML_error_handler( |
48 | | - int $errno, |
49 | | - string $errstr, |
50 | | - ?string $errfile = null, |
51 | | - int $errline = 0, |
52 | | - /** @scrutinizer-unused */ $errcontext = null |
53 | | -): bool { |
54 | | - if (Logger::isErrorMasked($errno)) { |
55 | | - // masked error |
56 | | - return false; |
57 | | - } |
58 | | - |
59 | | - static $limit = 5; |
60 | | - $limit -= 1; |
61 | | - if ($limit < 0) { |
62 | | - // we have reached the limit in the number of backtraces we will log |
63 | | - return false; |
64 | | - } |
65 | | - |
66 | | - $levels = [ |
67 | | - \E_DEPRECATED => 'Deprecated', |
68 | | - \E_USER_DEPRECATED => 'User Deprecated', |
69 | | - \E_NOTICE => 'Notice', |
70 | | - \E_USER_NOTICE => 'User Notice', |
71 | | - \E_STRICT => 'Runtime Notice', |
72 | | - \E_WARNING => 'Warning', |
73 | | - \E_USER_WARNING => 'User Warning', |
74 | | - \E_COMPILE_WARNING => 'Compile Warning', |
75 | | - \E_CORE_WARNING => 'Core Warning', |
76 | | - \E_USER_ERROR => 'User Error', |
77 | | - \E_RECOVERABLE_ERROR => 'Catchable Fatal Error', |
78 | | - \E_COMPILE_ERROR => 'Compile Error', |
79 | | - \E_PARSE => 'Parse Error', |
80 | | - \E_ERROR => 'Error', |
81 | | - \E_CORE_ERROR => 'Core Error', |
82 | | - ]; |
83 | | - |
84 | | - // show an error with a full backtrace |
85 | | - $context = (is_null($errfile) ? '' : " at $errfile:$errline"); |
86 | | - $e = new Error\Exception($levels[$errno] . ' - ' . $errstr . $context); |
87 | | - $e->logError(); |
88 | | - |
89 | | - // resume normal error processing |
90 | | - return false; |
91 | | -} |
92 | | - |
93 | | -set_error_handler('SimpleSAML_error_handler'); |
| 17 | +$errorHandler = new Error\ErrorHandler(); |
| 18 | +set_error_handler([$errorHandler, 'customErrorHandler']); |
94 | 19 |
|
95 | 20 | try { |
96 | 21 | Configuration::getInstance(); |
|
0 commit comments