1 | <?php |
||
28 | class ExceptionWrapper extends Component implements MiddlewareInterface, LoggerAwareInterface |
||
29 | { |
||
30 | use LoggerTrait; |
||
31 | |||
32 | /** |
||
33 | * Format to be used for log messages in cases where http error caused by client request. |
||
34 | */ |
||
35 | const LOG_FORMAT = "{scheme}://{host}{path} caused the error {code} ({message}) by client {remote}."; |
||
36 | |||
37 | /** |
||
38 | * Contain list of error pages. |
||
39 | * |
||
40 | * @var HttpConfig |
||
41 | */ |
||
42 | protected $httpConfig = null; |
||
43 | |||
44 | /** |
||
45 | * Required to get ErrorWriter on demand and fetch proper logger. |
||
46 | * |
||
47 | * @invisible |
||
48 | * @var ContainerInterface |
||
49 | */ |
||
50 | protected $container = null; |
||
51 | |||
52 | /** |
||
53 | * @param HttpConfig $httpConfig |
||
54 | * @param ContainerInterface $container |
||
55 | */ |
||
56 | public function __construct(HttpConfig $httpConfig, ContainerInterface $container) |
||
61 | |||
62 | /** |
||
63 | * {@inheritdoc} |
||
64 | */ |
||
65 | public function __invoke(Request $request, Response $response, callable $next) |
||
78 | |||
79 | /** |
||
80 | * Add error to error log. |
||
81 | * |
||
82 | * @param Request $request |
||
83 | * @param ClientException $exception |
||
84 | */ |
||
85 | private function logError(Request $request, ClientException $exception) |
||
96 | |||
97 | /** |
||
98 | * Instance of ErrorWriter. |
||
99 | * |
||
100 | * @return ErrorWriter |
||
101 | */ |
||
102 | protected function errorWriter(): ErrorWriter |
||
106 | |||
107 | /** |
||
108 | * Try to locate client ip. To be used for debug purposes only! |
||
109 | * |
||
110 | * @param \Psr\Http\Message\ServerRequestInterface $request |
||
111 | * |
||
112 | * @return string |
||
113 | */ |
||
114 | private function findIp(ServerRequestInterface $request): string |
||
118 | } |
||
119 |