@@ -29,73 +29,73 @@ |
||
29 | 29 | use OCP\ILogger; |
30 | 30 | |
31 | 31 | class ErrorHandler { |
32 | - /** @var ILogger */ |
|
33 | - private static $logger; |
|
32 | + /** @var ILogger */ |
|
33 | + private static $logger; |
|
34 | 34 | |
35 | - /** |
|
36 | - * remove password in URLs |
|
37 | - * @param string $msg |
|
38 | - * @return string |
|
39 | - */ |
|
40 | - protected static function removePassword($msg) { |
|
41 | - return preg_replace('/\/\/(.*):(.*)@/', '//xxx:xxx@', $msg); |
|
42 | - } |
|
35 | + /** |
|
36 | + * remove password in URLs |
|
37 | + * @param string $msg |
|
38 | + * @return string |
|
39 | + */ |
|
40 | + protected static function removePassword($msg) { |
|
41 | + return preg_replace('/\/\/(.*):(.*)@/', '//xxx:xxx@', $msg); |
|
42 | + } |
|
43 | 43 | |
44 | - public static function register($debug=false) { |
|
45 | - $handler = new ErrorHandler(); |
|
44 | + public static function register($debug=false) { |
|
45 | + $handler = new ErrorHandler(); |
|
46 | 46 | |
47 | - if ($debug) { |
|
48 | - set_error_handler([$handler, 'onAll'], E_ALL); |
|
49 | - if (\OC::$CLI) { |
|
50 | - set_exception_handler(['OC_Template', 'printExceptionErrorPage']); |
|
51 | - } |
|
52 | - } else { |
|
53 | - set_error_handler([$handler, 'onError']); |
|
54 | - } |
|
55 | - register_shutdown_function([$handler, 'onShutdown']); |
|
56 | - set_exception_handler([$handler, 'onException']); |
|
57 | - } |
|
47 | + if ($debug) { |
|
48 | + set_error_handler([$handler, 'onAll'], E_ALL); |
|
49 | + if (\OC::$CLI) { |
|
50 | + set_exception_handler(['OC_Template', 'printExceptionErrorPage']); |
|
51 | + } |
|
52 | + } else { |
|
53 | + set_error_handler([$handler, 'onError']); |
|
54 | + } |
|
55 | + register_shutdown_function([$handler, 'onShutdown']); |
|
56 | + set_exception_handler([$handler, 'onException']); |
|
57 | + } |
|
58 | 58 | |
59 | - public static function setLogger(ILogger $logger) { |
|
60 | - self::$logger = $logger; |
|
61 | - } |
|
59 | + public static function setLogger(ILogger $logger) { |
|
60 | + self::$logger = $logger; |
|
61 | + } |
|
62 | 62 | |
63 | - //Fatal errors handler |
|
64 | - public static function onShutdown() { |
|
65 | - $error = error_get_last(); |
|
66 | - if ($error && self::$logger) { |
|
67 | - //ob_end_clean(); |
|
68 | - $msg = $error['message'] . ' at ' . $error['file'] . '#' . $error['line']; |
|
69 | - self::$logger->critical(self::removePassword($msg), ['app' => 'PHP']); |
|
70 | - } |
|
71 | - } |
|
63 | + //Fatal errors handler |
|
64 | + public static function onShutdown() { |
|
65 | + $error = error_get_last(); |
|
66 | + if ($error && self::$logger) { |
|
67 | + //ob_end_clean(); |
|
68 | + $msg = $error['message'] . ' at ' . $error['file'] . '#' . $error['line']; |
|
69 | + self::$logger->critical(self::removePassword($msg), ['app' => 'PHP']); |
|
70 | + } |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * Uncaught exception handler |
|
75 | - * |
|
76 | - * @param \Exception $exception |
|
77 | - */ |
|
78 | - public static function onException($exception) { |
|
79 | - $class = get_class($exception); |
|
80 | - $msg = $exception->getMessage(); |
|
81 | - $msg = "$class: $msg at " . $exception->getFile() . '#' . $exception->getLine(); |
|
82 | - self::$logger->critical(self::removePassword($msg), ['app' => 'PHP']); |
|
83 | - } |
|
73 | + /** |
|
74 | + * Uncaught exception handler |
|
75 | + * |
|
76 | + * @param \Exception $exception |
|
77 | + */ |
|
78 | + public static function onException($exception) { |
|
79 | + $class = get_class($exception); |
|
80 | + $msg = $exception->getMessage(); |
|
81 | + $msg = "$class: $msg at " . $exception->getFile() . '#' . $exception->getLine(); |
|
82 | + self::$logger->critical(self::removePassword($msg), ['app' => 'PHP']); |
|
83 | + } |
|
84 | 84 | |
85 | - //Recoverable errors handler |
|
86 | - public static function onError($number, $message, $file, $line) { |
|
87 | - if (error_reporting() === 0) { |
|
88 | - return; |
|
89 | - } |
|
90 | - $msg = $message . ' at ' . $file . '#' . $line; |
|
91 | - $e = new \Error(self::removePassword($msg)); |
|
92 | - self::$logger->logException($e, ['app' => 'PHP']); |
|
93 | - } |
|
85 | + //Recoverable errors handler |
|
86 | + public static function onError($number, $message, $file, $line) { |
|
87 | + if (error_reporting() === 0) { |
|
88 | + return; |
|
89 | + } |
|
90 | + $msg = $message . ' at ' . $file . '#' . $line; |
|
91 | + $e = new \Error(self::removePassword($msg)); |
|
92 | + self::$logger->logException($e, ['app' => 'PHP']); |
|
93 | + } |
|
94 | 94 | |
95 | - //Recoverable handler which catch all errors, warnings and notices |
|
96 | - public static function onAll($number, $message, $file, $line) { |
|
97 | - $msg = $message . ' at ' . $file . '#' . $line; |
|
98 | - $e = new \Error(self::removePassword($msg)); |
|
99 | - self::$logger->logException($e, ['app' => 'PHP', 'level' => 0]); |
|
100 | - } |
|
95 | + //Recoverable handler which catch all errors, warnings and notices |
|
96 | + public static function onAll($number, $message, $file, $line) { |
|
97 | + $msg = $message . ' at ' . $file . '#' . $line; |
|
98 | + $e = new \Error(self::removePassword($msg)); |
|
99 | + self::$logger->logException($e, ['app' => 'PHP', 'level' => 0]); |
|
100 | + } |
|
101 | 101 | } |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | return preg_replace('/\/\/(.*):(.*)@/', '//xxx:xxx@', $msg); |
42 | 42 | } |
43 | 43 | |
44 | - public static function register($debug=false) { |
|
44 | + public static function register($debug = false) { |
|
45 | 45 | $handler = new ErrorHandler(); |
46 | 46 | |
47 | 47 | if ($debug) { |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | $error = error_get_last(); |
66 | 66 | if ($error && self::$logger) { |
67 | 67 | //ob_end_clean(); |
68 | - $msg = $error['message'] . ' at ' . $error['file'] . '#' . $error['line']; |
|
68 | + $msg = $error['message'].' at '.$error['file'].'#'.$error['line']; |
|
69 | 69 | self::$logger->critical(self::removePassword($msg), ['app' => 'PHP']); |
70 | 70 | } |
71 | 71 | } |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | public static function onException($exception) { |
79 | 79 | $class = get_class($exception); |
80 | 80 | $msg = $exception->getMessage(); |
81 | - $msg = "$class: $msg at " . $exception->getFile() . '#' . $exception->getLine(); |
|
81 | + $msg = "$class: $msg at ".$exception->getFile().'#'.$exception->getLine(); |
|
82 | 82 | self::$logger->critical(self::removePassword($msg), ['app' => 'PHP']); |
83 | 83 | } |
84 | 84 | |
@@ -87,14 +87,14 @@ discard block |
||
87 | 87 | if (error_reporting() === 0) { |
88 | 88 | return; |
89 | 89 | } |
90 | - $msg = $message . ' at ' . $file . '#' . $line; |
|
90 | + $msg = $message.' at '.$file.'#'.$line; |
|
91 | 91 | $e = new \Error(self::removePassword($msg)); |
92 | 92 | self::$logger->logException($e, ['app' => 'PHP']); |
93 | 93 | } |
94 | 94 | |
95 | 95 | //Recoverable handler which catch all errors, warnings and notices |
96 | 96 | public static function onAll($number, $message, $file, $line) { |
97 | - $msg = $message . ' at ' . $file . '#' . $line; |
|
97 | + $msg = $message.' at '.$file.'#'.$line; |
|
98 | 98 | $e = new \Error(self::removePassword($msg)); |
99 | 99 | self::$logger->logException($e, ['app' => 'PHP', 'level' => 0]); |
100 | 100 | } |