1 | <?php |
||
8 | trait HandleUncaughtException |
||
9 | { |
||
10 | /** |
||
11 | * @var callable|false |
||
12 | */ |
||
13 | protected $chainedExceptionHandler; |
||
14 | |||
15 | |||
16 | /** |
||
17 | * Log the following exception classes (and subclasses) |
||
18 | * @var array |
||
19 | */ |
||
20 | protected $logExceptionClasses = []; |
||
21 | |||
22 | |||
23 | /** |
||
24 | * Wrapper method for `set_error_handler` |
||
25 | * |
||
26 | * @param callable $callback |
||
27 | * @param int $error_types |
||
28 | * @return callable|null |
||
29 | */ |
||
30 | abstract protected function setErrorHandler($callback, $error_types = E_ALL); |
||
31 | |||
32 | /** |
||
33 | * Wrapper method for `set_exception_handler` |
||
34 | * |
||
35 | * @param callable $callback |
||
36 | * @return callable|null |
||
37 | */ |
||
38 | abstract protected function setExceptionHandler($callback); |
||
39 | |||
40 | /** |
||
41 | * Log an error or exception |
||
42 | * |
||
43 | * @param \Exception|\Error $error |
||
44 | */ |
||
45 | abstract public function log($error); |
||
46 | |||
47 | |||
48 | /** |
||
49 | * Get the error handler that has been replaced. |
||
50 | * |
||
51 | * @return callable|false|null |
||
52 | */ |
||
53 | 2 | public function getChainedExceptionHandler() |
|
57 | |||
58 | /** |
||
59 | * Get a list of Exception and other Throwable classes that will be logged |
||
60 | * @return array |
||
61 | */ |
||
62 | 4 | public function getLoggedExceptionClasses() |
|
66 | |||
67 | |||
68 | /** |
||
69 | * Log these types of errors or exceptions |
||
70 | * |
||
71 | * @param string $class Exception class name |
||
72 | */ |
||
73 | 18 | protected function logUncaughtException($class) |
|
81 | |||
82 | |||
83 | /** |
||
84 | * Use the global error handler |
||
85 | */ |
||
86 | 18 | protected function initExceptionHandler() |
|
92 | |||
93 | /** |
||
94 | * Uncaught exception handler |
||
95 | * @ignore |
||
96 | * |
||
97 | * @param \Exception|\Error $exception |
||
98 | */ |
||
99 | 18 | public function handleException($exception) |
|
127 | } |
||
128 | |||
129 |
For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a
@return
doc comment to communicate to implementors of these methods what they are expected to return.