@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | RendererInterface $renderer, |
| 58 | 58 | ResponseFactoryInterface $responseFactory, |
| 59 | 59 | ContainerInterface $container |
| 60 | - ) { |
|
| 60 | + ){ |
|
| 61 | 61 | $this->suppressErrors = $suppressErrors; |
| 62 | 62 | $this->renderer = $renderer; |
| 63 | 63 | $this->responseFactory = $responseFactory; |
@@ -71,28 +71,28 @@ discard block |
||
| 71 | 71 | */ |
| 72 | 72 | public function process(Request $request, Handler $handler): Response |
| 73 | 73 | { |
| 74 | - try { |
|
| 74 | + try{ |
|
| 75 | 75 | return $handler->handle($request); |
| 76 | - } catch (ClientException | RouterException $e) { |
|
| 77 | - if ($e instanceof ClientException) { |
|
| 76 | + }catch (ClientException | RouterException $e){ |
|
| 77 | + if ($e instanceof ClientException){ |
|
| 78 | 78 | $code = $e->getCode(); |
| 79 | - } else { |
|
| 79 | + }else{ |
|
| 80 | 80 | $code = 404; |
| 81 | 81 | } |
| 82 | - } catch (\Throwable $e) { |
|
| 82 | + }catch (\Throwable $e){ |
|
| 83 | 83 | $snapshotter = $this->getOptional(SnapshotterInterface::class); |
| 84 | - if ($snapshotter !== null) { |
|
| 84 | + if ($snapshotter !== null){ |
|
| 85 | 85 | /** @var SnapshotterInterface $snapshotter */ |
| 86 | 86 | $snapshotter->register($e); |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - if ($e instanceof ClientException) { |
|
| 89 | + if ($e instanceof ClientException){ |
|
| 90 | 90 | $code = $e->getCode(); |
| 91 | - } else { |
|
| 91 | + }else{ |
|
| 92 | 92 | $code = 500; |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - if (!$this->suppressErrors) { |
|
| 95 | + if (!$this->suppressErrors){ |
|
| 96 | 96 | return $this->renderException($request, $e); |
| 97 | 97 | } |
| 98 | 98 | } |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | { |
| 114 | 114 | $response = $this->responseFactory->createResponse(500); |
| 115 | 115 | |
| 116 | - if ($request->getHeaderLine('Accept') == 'application/json') { |
|
| 116 | + if ($request->getHeaderLine('Accept') == 'application/json'){ |
|
| 117 | 117 | $response = $response->withHeader('Content-Type', 'application/json'); |
| 118 | 118 | $handler = new JsonHandler(); |
| 119 | 119 | $response->getBody()->write(json_encode( |
@@ -123,10 +123,10 @@ discard block |
||
| 123 | 123 | true |
| 124 | 124 | ) |
| 125 | 125 | )); |
| 126 | - } else { |
|
| 126 | + }else{ |
|
| 127 | 127 | $handler = new HtmlHandler(); |
| 128 | 128 | $state = $this->getOptional(StateInterface::class); |
| 129 | - if ($state !== null) { |
|
| 129 | + if ($state !== null){ |
|
| 130 | 130 | $handler = $handler->withState($state); |
| 131 | 131 | } |
| 132 | 132 | |
@@ -160,9 +160,9 @@ discard block |
||
| 160 | 160 | */ |
| 161 | 161 | private function getOptional(string $class) |
| 162 | 162 | { |
| 163 | - try { |
|
| 163 | + try{ |
|
| 164 | 164 | return $this->container->get($class); |
| 165 | - } catch (\Throwable | ContainerExceptionInterface $se) { |
|
| 165 | + }catch (\Throwable | ContainerExceptionInterface $se){ |
|
| 166 | 166 | return null; |
| 167 | 167 | } |
| 168 | 168 | } |
@@ -71,28 +71,41 @@ discard block |
||
| 71 | 71 | */ |
| 72 | 72 | public function process(Request $request, Handler $handler): Response |
| 73 | 73 | { |
| 74 | - try { |
|
| 74 | + try |
|
| 75 | + { |
|
| 75 | 76 | return $handler->handle($request); |
| 76 | - } catch (ClientException | RouterException $e) { |
|
| 77 | - if ($e instanceof ClientException) { |
|
| 77 | + } |
|
| 78 | + catch (ClientException | RouterException $e) |
|
| 79 | + { |
|
| 80 | + if ($e instanceof ClientException) |
|
| 81 | + { |
|
| 78 | 82 | $code = $e->getCode(); |
| 79 | - } else { |
|
| 83 | + } |
|
| 84 | + else |
|
| 85 | + { |
|
| 80 | 86 | $code = 404; |
| 81 | 87 | } |
| 82 | - } catch (\Throwable $e) { |
|
| 88 | + } |
|
| 89 | + catch (\Throwable $e) |
|
| 90 | + { |
|
| 83 | 91 | $snapshotter = $this->getOptional(SnapshotterInterface::class); |
| 84 | - if ($snapshotter !== null) { |
|
| 92 | + if ($snapshotter !== null) |
|
| 93 | + { |
|
| 85 | 94 | /** @var SnapshotterInterface $snapshotter */ |
| 86 | 95 | $snapshotter->register($e); |
| 87 | 96 | } |
| 88 | 97 | |
| 89 | - if ($e instanceof ClientException) { |
|
| 98 | + if ($e instanceof ClientException) |
|
| 99 | + { |
|
| 90 | 100 | $code = $e->getCode(); |
| 91 | - } else { |
|
| 101 | + } |
|
| 102 | + else |
|
| 103 | + { |
|
| 92 | 104 | $code = 500; |
| 93 | 105 | } |
| 94 | 106 | |
| 95 | - if (!$this->suppressErrors) { |
|
| 107 | + if (!$this->suppressErrors) |
|
| 108 | + { |
|
| 96 | 109 | return $this->renderException($request, $e); |
| 97 | 110 | } |
| 98 | 111 | } |
@@ -113,7 +126,8 @@ discard block |
||
| 113 | 126 | { |
| 114 | 127 | $response = $this->responseFactory->createResponse(500); |
| 115 | 128 | |
| 116 | - if ($request->getHeaderLine('Accept') == 'application/json') { |
|
| 129 | + if ($request->getHeaderLine('Accept') == 'application/json') |
|
| 130 | + { |
|
| 117 | 131 | $response = $response->withHeader('Content-Type', 'application/json'); |
| 118 | 132 | $handler = new JsonHandler(); |
| 119 | 133 | $response->getBody()->write(json_encode( |
@@ -123,10 +137,13 @@ discard block |
||
| 123 | 137 | true |
| 124 | 138 | ) |
| 125 | 139 | )); |
| 126 | - } else { |
|
| 140 | + } |
|
| 141 | + else |
|
| 142 | + { |
|
| 127 | 143 | $handler = new HtmlHandler(); |
| 128 | 144 | $state = $this->getOptional(StateInterface::class); |
| 129 | - if ($state !== null) { |
|
| 145 | + if ($state !== null) |
|
| 146 | + { |
|
| 130 | 147 | $handler = $handler->withState($state); |
| 131 | 148 | } |
| 132 | 149 | |
@@ -160,9 +177,12 @@ discard block |
||
| 160 | 177 | */ |
| 161 | 178 | private function getOptional(string $class) |
| 162 | 179 | { |
| 163 | - try { |
|
| 180 | + try |
|
| 181 | + { |
|
| 164 | 182 | return $this->container->get($class); |
| 165 | - } catch (\Throwable | ContainerExceptionInterface $se) { |
|
| 183 | + } |
|
| 184 | + catch (\Throwable | ContainerExceptionInterface $se) |
|
| 185 | + { |
|
| 166 | 186 | return null; |
| 167 | 187 | } |
| 168 | 188 | } |