@@ -14,68 +14,68 @@ |
||
14 | 14 | use Throwable; |
15 | 15 | |
16 | 16 | class ErrorHandler { |
17 | - public function __construct( |
|
18 | - private LoggerInterface $logger, |
|
19 | - ) { |
|
20 | - } |
|
17 | + public function __construct( |
|
18 | + private LoggerInterface $logger, |
|
19 | + ) { |
|
20 | + } |
|
21 | 21 | |
22 | - /** |
|
23 | - * Remove password in URLs |
|
24 | - */ |
|
25 | - private static function removePassword(string $msg): string { |
|
26 | - return preg_replace('#//(.*):(.*)@#', '//xxx:xxx@', $msg); |
|
27 | - } |
|
22 | + /** |
|
23 | + * Remove password in URLs |
|
24 | + */ |
|
25 | + private static function removePassword(string $msg): string { |
|
26 | + return preg_replace('#//(.*):(.*)@#', '//xxx:xxx@', $msg); |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * Fatal errors handler |
|
31 | - */ |
|
32 | - public function onShutdown(): void { |
|
33 | - $error = error_get_last(); |
|
34 | - if ($error) { |
|
35 | - $msg = $error['message'] . ' at ' . $error['file'] . '#' . $error['line']; |
|
36 | - $this->logger->critical(self::removePassword($msg), ['app' => 'PHP']); |
|
37 | - } |
|
38 | - } |
|
29 | + /** |
|
30 | + * Fatal errors handler |
|
31 | + */ |
|
32 | + public function onShutdown(): void { |
|
33 | + $error = error_get_last(); |
|
34 | + if ($error) { |
|
35 | + $msg = $error['message'] . ' at ' . $error['file'] . '#' . $error['line']; |
|
36 | + $this->logger->critical(self::removePassword($msg), ['app' => 'PHP']); |
|
37 | + } |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * Uncaught exception handler |
|
42 | - */ |
|
43 | - public function onException(Throwable $exception): void { |
|
44 | - $class = get_class($exception); |
|
45 | - $msg = $exception->getMessage(); |
|
46 | - $msg = "$class: $msg at " . $exception->getFile() . '#' . $exception->getLine(); |
|
47 | - $this->logger->critical(self::removePassword($msg), ['app' => 'PHP']); |
|
48 | - } |
|
40 | + /** |
|
41 | + * Uncaught exception handler |
|
42 | + */ |
|
43 | + public function onException(Throwable $exception): void { |
|
44 | + $class = get_class($exception); |
|
45 | + $msg = $exception->getMessage(); |
|
46 | + $msg = "$class: $msg at " . $exception->getFile() . '#' . $exception->getLine(); |
|
47 | + $this->logger->critical(self::removePassword($msg), ['app' => 'PHP']); |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * Recoverable errors handler |
|
52 | - */ |
|
53 | - public function onError(int $number, string $message, string $file, int $line): bool { |
|
54 | - if (!(error_reporting() & $number)) { |
|
55 | - return true; |
|
56 | - } |
|
57 | - $msg = $message . ' at ' . $file . '#' . $line; |
|
58 | - $e = new Error(self::removePassword($msg)); |
|
59 | - $this->logger->log(self::errnoToLogLevel($number), $e->getMessage(), ['app' => 'PHP']); |
|
60 | - return true; |
|
61 | - } |
|
50 | + /** |
|
51 | + * Recoverable errors handler |
|
52 | + */ |
|
53 | + public function onError(int $number, string $message, string $file, int $line): bool { |
|
54 | + if (!(error_reporting() & $number)) { |
|
55 | + return true; |
|
56 | + } |
|
57 | + $msg = $message . ' at ' . $file . '#' . $line; |
|
58 | + $e = new Error(self::removePassword($msg)); |
|
59 | + $this->logger->log(self::errnoToLogLevel($number), $e->getMessage(), ['app' => 'PHP']); |
|
60 | + return true; |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * Recoverable handler which catch all errors, warnings and notices |
|
65 | - */ |
|
66 | - public function onAll(int $number, string $message, string $file, int $line): bool { |
|
67 | - $msg = $message . ' at ' . $file . '#' . $line; |
|
68 | - $e = new Error(self::removePassword($msg)); |
|
69 | - $this->logger->log(self::errnoToLogLevel($number), $e->getMessage(), ['app' => 'PHP']); |
|
70 | - return true; |
|
71 | - } |
|
63 | + /** |
|
64 | + * Recoverable handler which catch all errors, warnings and notices |
|
65 | + */ |
|
66 | + public function onAll(int $number, string $message, string $file, int $line): bool { |
|
67 | + $msg = $message . ' at ' . $file . '#' . $line; |
|
68 | + $e = new Error(self::removePassword($msg)); |
|
69 | + $this->logger->log(self::errnoToLogLevel($number), $e->getMessage(), ['app' => 'PHP']); |
|
70 | + return true; |
|
71 | + } |
|
72 | 72 | |
73 | - private static function errnoToLogLevel(int $errno): int { |
|
74 | - return match ($errno) { |
|
75 | - E_WARNING, E_USER_WARNING => ILogger::WARN, |
|
76 | - E_DEPRECATED, E_USER_DEPRECATED => ILogger::DEBUG, |
|
77 | - E_NOTICE, E_USER_NOTICE => ILogger::INFO, |
|
78 | - default => ILogger::ERROR, |
|
79 | - }; |
|
80 | - } |
|
73 | + private static function errnoToLogLevel(int $errno): int { |
|
74 | + return match ($errno) { |
|
75 | + E_WARNING, E_USER_WARNING => ILogger::WARN, |
|
76 | + E_DEPRECATED, E_USER_DEPRECATED => ILogger::DEBUG, |
|
77 | + E_NOTICE, E_USER_NOTICE => ILogger::INFO, |
|
78 | + default => ILogger::ERROR, |
|
79 | + }; |
|
80 | + } |
|
81 | 81 | } |