1 | <?php |
||
27 | final class ErrorHandler |
||
28 | { |
||
29 | /** |
||
30 | * @var string[] |
||
31 | */ |
||
32 | private static $errors = array(); |
||
33 | |||
34 | /** |
||
35 | * Registers the error handler. |
||
36 | */ |
||
37 | 5 | public static function register() |
|
38 | { |
||
39 | 5 | self::$errors = array(); |
|
40 | |||
41 | 5 | set_error_handler(array(__CLASS__, 'handleError')); |
|
42 | 5 | } |
|
43 | |||
44 | /** |
||
45 | * Unregisters the error handler. |
||
46 | */ |
||
47 | 5 | public static function unregister() |
|
51 | |||
52 | /** |
||
53 | * Returns the caught errors. |
||
54 | * |
||
55 | * @return string[] The caught error messages. |
||
56 | */ |
||
57 | public static function getErrors() |
||
61 | |||
62 | /** |
||
63 | * Returns whether the handler caught any errors. |
||
64 | * |
||
65 | * @return bool Returns `true` if the handler caught errors and `false` |
||
66 | * otherwise. |
||
67 | */ |
||
68 | 5 | public static function hasErrors() |
|
72 | |||
73 | /** |
||
74 | * Handles an error. |
||
75 | * |
||
76 | * @param int $code The error code. |
||
77 | * @param string $message The error message. |
||
78 | */ |
||
79 | public static function handleError($code, $message) |
||
83 | |||
84 | private function __construct() |
||
87 | } |
||
88 |