1 | <?php |
||
12 | class ErrorHandler implements LoggerAwareInterface |
||
13 | { |
||
14 | use ErrorHandler\Logging; |
||
15 | use ErrorHandler\ErrorCodes; |
||
16 | use ErrorHandler\HandleUncaughtError; |
||
17 | use ErrorHandler\HandleShutdownError; |
||
18 | use ErrorHandler\HandleUncaughtException; |
||
19 | use ErrorHandler\FunctionWrapper; |
||
20 | |||
21 | |||
22 | /** |
||
23 | * @var \Exception|\Error |
||
24 | */ |
||
25 | protected $error; |
||
26 | |||
27 | /** |
||
28 | * @var callback |
||
29 | */ |
||
30 | protected $onFatalError; |
||
31 | |||
32 | |||
33 | /** |
||
34 | * Set the caught error |
||
35 | * |
||
36 | * @param \Throwable|\Exception|\Error |
||
37 | */ |
||
38 | 4 | public function setError($error) |
|
48 | |||
49 | /** |
||
50 | * Get the caught error |
||
51 | * |
||
52 | * @return \Throwable|\Exception|\Error |
||
53 | */ |
||
54 | 4 | public function getError() |
|
58 | |||
59 | |||
60 | |||
61 | /** |
||
62 | * Use this error handler as middleware |
||
63 | */ |
||
64 | 2 | public function asMiddleware() |
|
68 | |||
69 | |||
70 | /** |
||
71 | * Log these types of errors or exceptions |
||
72 | * |
||
73 | * @param int|string $type E_* contants as binary set OR Exception class name |
||
74 | */ |
||
75 | 84 | public function logUncaught($type) |
|
85 | |||
86 | |||
87 | /** |
||
88 | * Set a callback for when the script dies because of a fatal, non-catchable error. |
||
89 | * The callback should have an `ErrorException` as only argument. |
||
90 | * |
||
91 | * @param callable $callback |
||
92 | * @param boolean $clearOutput Clear the output buffer before calling the callback |
||
93 | */ |
||
94 | 8 | public function onFatalError($callback, $clearOutput = false) |
|
105 | |||
106 | /** |
||
107 | * Run the fatal error callback |
||
108 | * |
||
109 | * @param \Exception|\Error $error |
||
110 | */ |
||
111 | 28 | protected function callOnFatalError($error) |
|
117 | |||
118 | /** |
||
119 | * Clear and destroy all the output buffers |
||
120 | * @codeCoverageIgnore |
||
121 | */ |
||
122 | protected function clearOutputBuffer() |
||
128 | } |
||
129 | |||
130 |