@@ -7,67 +7,67 @@ |
||
7 | 7 | |
8 | 8 | class Handler |
9 | 9 | { |
10 | - const ERROR_HANDLER = 'handleError'; |
|
11 | - const EXCEPTION_HANDLER = 'handleException'; |
|
10 | + const ERROR_HANDLER = 'handleError'; |
|
11 | + const EXCEPTION_HANDLER = 'handleException'; |
|
12 | 12 | |
13 | - /** |
|
14 | - * @var FormatterInterface |
|
15 | - */ |
|
16 | - private $formatter; |
|
13 | + /** |
|
14 | + * @var FormatterInterface |
|
15 | + */ |
|
16 | + private $formatter; |
|
17 | 17 | |
18 | - /** |
|
19 | - * Handler constructor. |
|
20 | - * |
|
21 | - * @param FormatterInterface $formatter |
|
22 | - */ |
|
23 | - public function __construct(FormatterInterface $formatter) |
|
24 | - { |
|
25 | - $this->formatter = $formatter; |
|
26 | - $this->registerErrorHandler(); |
|
27 | - $this->registerExceptionHandler(); |
|
28 | - } |
|
18 | + /** |
|
19 | + * Handler constructor. |
|
20 | + * |
|
21 | + * @param FormatterInterface $formatter |
|
22 | + */ |
|
23 | + public function __construct(FormatterInterface $formatter) |
|
24 | + { |
|
25 | + $this->formatter = $formatter; |
|
26 | + $this->registerErrorHandler(); |
|
27 | + $this->registerExceptionHandler(); |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * Register the PHP error handler. |
|
32 | - * |
|
33 | - * @return void |
|
34 | - */ |
|
35 | - protected function registerErrorHandler() |
|
36 | - { |
|
37 | - set_error_handler(array($this, self::ERROR_HANDLER)); |
|
38 | - } |
|
30 | + /** |
|
31 | + * Register the PHP error handler. |
|
32 | + * |
|
33 | + * @return void |
|
34 | + */ |
|
35 | + protected function registerErrorHandler() |
|
36 | + { |
|
37 | + set_error_handler(array($this, self::ERROR_HANDLER)); |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * Register the PHP exception handler. |
|
42 | - * |
|
43 | - * @return void |
|
44 | - */ |
|
45 | - protected function registerExceptionHandler() |
|
46 | - { |
|
47 | - set_exception_handler(array($this, self::EXCEPTION_HANDLER)); |
|
48 | - } |
|
40 | + /** |
|
41 | + * Register the PHP exception handler. |
|
42 | + * |
|
43 | + * @return void |
|
44 | + */ |
|
45 | + protected function registerExceptionHandler() |
|
46 | + { |
|
47 | + set_exception_handler(array($this, self::EXCEPTION_HANDLER)); |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * @param int $level |
|
52 | - * @param string $message |
|
53 | - * @param string $file |
|
54 | - * @param int $line |
|
55 | - * @param array $context |
|
56 | - * |
|
57 | - * @throws ErrorException |
|
58 | - */ |
|
59 | - public function handleError(int $level, string $message, string $file = '', int $line = 0, array $context = []) |
|
60 | - { |
|
61 | - throw new ErrorException($message, 0, $level, $file, $line); |
|
62 | - } |
|
50 | + /** |
|
51 | + * @param int $level |
|
52 | + * @param string $message |
|
53 | + * @param string $file |
|
54 | + * @param int $line |
|
55 | + * @param array $context |
|
56 | + * |
|
57 | + * @throws ErrorException |
|
58 | + */ |
|
59 | + public function handleError(int $level, string $message, string $file = '', int $line = 0, array $context = []) |
|
60 | + { |
|
61 | + throw new ErrorException($message, 0, $level, $file, $line); |
|
62 | + } |
|
63 | 63 | |
64 | - public function handleException(\Throwable $e) |
|
65 | - { |
|
66 | - ob_start(); |
|
67 | - $response = json_encode($this->formatter->format($e)); |
|
68 | - ob_end_clean(); |
|
69 | - http_response_code(500); |
|
70 | - print $response; |
|
71 | - return; |
|
72 | - } |
|
64 | + public function handleException(\Throwable $e) |
|
65 | + { |
|
66 | + ob_start(); |
|
67 | + $response = json_encode($this->formatter->format($e)); |
|
68 | + ob_end_clean(); |
|
69 | + http_response_code(500); |
|
70 | + print $response; |
|
71 | + return; |
|
72 | + } |
|
73 | 73 | } |
74 | 74 | \ No newline at end of file |
@@ -7,13 +7,13 @@ |
||
7 | 7 | class DefaultFormatter implements FormatterInterface |
8 | 8 | { |
9 | 9 | |
10 | - public function format(\Throwable $e): array |
|
11 | - { |
|
12 | - return [ |
|
13 | - 'message' => $e->getMessage(), |
|
14 | - 'file' => $e->getFile(), |
|
15 | - 'line' => $e->getLine(), |
|
16 | - 'trace' => $e->getTrace(), |
|
17 | - ]; |
|
18 | - } |
|
10 | + public function format(\Throwable $e): array |
|
11 | + { |
|
12 | + return [ |
|
13 | + 'message' => $e->getMessage(), |
|
14 | + 'file' => $e->getFile(), |
|
15 | + 'line' => $e->getLine(), |
|
16 | + 'trace' => $e->getTrace(), |
|
17 | + ]; |
|
18 | + } |
|
19 | 19 | } |
20 | 20 | \ No newline at end of file |
@@ -7,12 +7,12 @@ |
||
7 | 7 | |
8 | 8 | interface Middleware |
9 | 9 | { |
10 | - /** |
|
11 | - * @param ServerRequestInterface $request |
|
12 | - * @param ResponseInterface $response |
|
13 | - * @param callable $next |
|
14 | - * |
|
15 | - * @return ResponseInterface |
|
16 | - */ |
|
17 | - public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next) : ResponseInterface; |
|
10 | + /** |
|
11 | + * @param ServerRequestInterface $request |
|
12 | + * @param ResponseInterface $response |
|
13 | + * @param callable $next |
|
14 | + * |
|
15 | + * @return ResponseInterface |
|
16 | + */ |
|
17 | + public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next) : ResponseInterface; |
|
18 | 18 | } |