@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | RendererInterface $renderer, |
60 | 60 | ResponseFactoryInterface $responseFactory, |
61 | 61 | ContainerInterface $container |
62 | - ) { |
|
62 | + ){ |
|
63 | 63 | $this->suppressErrors = $suppressErrors; |
64 | 64 | $this->renderer = $renderer; |
65 | 65 | $this->responseFactory = $responseFactory; |
@@ -73,22 +73,22 @@ discard block |
||
73 | 73 | */ |
74 | 74 | public function process(Request $request, Handler $handler): Response |
75 | 75 | { |
76 | - try { |
|
76 | + try{ |
|
77 | 77 | return $handler->handle($request); |
78 | - } catch (ClientException | RouterException $e) { |
|
79 | - if ($e instanceof ClientException) { |
|
78 | + }catch (ClientException | RouterException $e){ |
|
79 | + if ($e instanceof ClientException){ |
|
80 | 80 | $code = $e->getCode(); |
81 | - } else { |
|
81 | + }else{ |
|
82 | 82 | $code = 404; |
83 | 83 | } |
84 | - } catch (\Throwable $e) { |
|
84 | + }catch (\Throwable $e){ |
|
85 | 85 | $snapshotter = $this->getOptional(SnapshotterInterface::class); |
86 | - if ($snapshotter !== null) { |
|
86 | + if ($snapshotter !== null){ |
|
87 | 87 | /** @var SnapshotterInterface $snapshotter */ |
88 | 88 | $snapshotter->register($e); |
89 | 89 | } |
90 | 90 | |
91 | - if (!$this->suppressErrors->suppressed()) { |
|
91 | + if (!$this->suppressErrors->suppressed()){ |
|
92 | 92 | return $this->renderError($request, $e); |
93 | 93 | } |
94 | 94 | |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | { |
112 | 112 | $response = $this->responseFactory->createResponse(500); |
113 | 113 | |
114 | - if ($request->getHeaderLine('Accept') === 'application/json') { |
|
114 | + if ($request->getHeaderLine('Accept') === 'application/json'){ |
|
115 | 115 | $response = $response->withHeader('Content-Type', 'application/json'); |
116 | 116 | $handler = new JsonHandler(); |
117 | 117 | $response->getBody()->write( |
@@ -123,10 +123,10 @@ discard block |
||
123 | 123 | ) |
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 | |
@@ -162,9 +162,9 @@ discard block |
||
162 | 162 | */ |
163 | 163 | private function getOptional(string $class) |
164 | 164 | { |
165 | - try { |
|
165 | + try{ |
|
166 | 166 | return $this->container->get($class); |
167 | - } catch (\Throwable | ContainerExceptionInterface $se) { |
|
167 | + }catch (\Throwable | ContainerExceptionInterface $se){ |
|
168 | 168 | return null; |
169 | 169 | } |
170 | 170 | } |
@@ -73,22 +73,32 @@ discard block |
||
73 | 73 | */ |
74 | 74 | public function process(Request $request, Handler $handler): Response |
75 | 75 | { |
76 | - try { |
|
76 | + try |
|
77 | + { |
|
77 | 78 | return $handler->handle($request); |
78 | - } catch (ClientException | RouterException $e) { |
|
79 | - if ($e instanceof ClientException) { |
|
79 | + } |
|
80 | + catch (ClientException | RouterException $e) |
|
81 | + { |
|
82 | + if ($e instanceof ClientException) |
|
83 | + { |
|
80 | 84 | $code = $e->getCode(); |
81 | - } else { |
|
85 | + } |
|
86 | + else |
|
87 | + { |
|
82 | 88 | $code = 404; |
83 | 89 | } |
84 | - } catch (\Throwable $e) { |
|
90 | + } |
|
91 | + catch (\Throwable $e) |
|
92 | + { |
|
85 | 93 | $snapshotter = $this->getOptional(SnapshotterInterface::class); |
86 | - if ($snapshotter !== null) { |
|
94 | + if ($snapshotter !== null) |
|
95 | + { |
|
87 | 96 | /** @var SnapshotterInterface $snapshotter */ |
88 | 97 | $snapshotter->register($e); |
89 | 98 | } |
90 | 99 | |
91 | - if (!$this->suppressErrors->suppressed()) { |
|
100 | + if (!$this->suppressErrors->suppressed()) |
|
101 | + { |
|
92 | 102 | return $this->renderError($request, $e); |
93 | 103 | } |
94 | 104 | |
@@ -111,7 +121,8 @@ discard block |
||
111 | 121 | { |
112 | 122 | $response = $this->responseFactory->createResponse(500); |
113 | 123 | |
114 | - if ($request->getHeaderLine('Accept') === 'application/json') { |
|
124 | + if ($request->getHeaderLine('Accept') === 'application/json') |
|
125 | + { |
|
115 | 126 | $response = $response->withHeader('Content-Type', 'application/json'); |
116 | 127 | $handler = new JsonHandler(); |
117 | 128 | $response->getBody()->write( |
@@ -123,10 +134,13 @@ discard block |
||
123 | 134 | ) |
124 | 135 | ) |
125 | 136 | ); |
126 | - } else { |
|
137 | + } |
|
138 | + else |
|
139 | + { |
|
127 | 140 | $handler = new HtmlHandler(); |
128 | 141 | $state = $this->getOptional(StateInterface::class); |
129 | - if ($state !== null) { |
|
142 | + if ($state !== null) |
|
143 | + { |
|
130 | 144 | $handler = $handler->withState($state); |
131 | 145 | } |
132 | 146 | |
@@ -162,9 +176,12 @@ discard block |
||
162 | 176 | */ |
163 | 177 | private function getOptional(string $class) |
164 | 178 | { |
165 | - try { |
|
179 | + try |
|
180 | + { |
|
166 | 181 | return $this->container->get($class); |
167 | - } catch (\Throwable | ContainerExceptionInterface $se) { |
|
182 | + } |
|
183 | + catch (\Throwable | ContainerExceptionInterface $se) |
|
184 | + { |
|
168 | 185 | return null; |
169 | 186 | } |
170 | 187 | } |