@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | private readonly ScopeInterface $scope, |
| 43 | 43 | private readonly ResponseFactoryInterface $responseFactory, |
| 44 | 44 | ?TracerInterface $tracer = null |
| 45 | - ) { |
|
| 45 | + ){ |
|
| 46 | 46 | $this->tracer = $tracer ?? new NullTracer($scope); |
| 47 | 47 | } |
| 48 | 48 | |
@@ -89,9 +89,9 @@ discard block |
||
| 89 | 89 | $output = ''; |
| 90 | 90 | |
| 91 | 91 | $response = $this->responseFactory->createResponse(200); |
| 92 | - try { |
|
| 92 | + try{ |
|
| 93 | 93 | $action = $this->verbActions |
| 94 | - ? \strtolower($request->getMethod()) . \ucfirst($this->action) |
|
| 94 | + ? \strtolower($request->getMethod()).\ucfirst($this->action) |
|
| 95 | 95 | : $this->action; |
| 96 | 96 | |
| 97 | 97 | // run the core withing PSR-7 Request/Response scope |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | Response::class => $response, |
| 102 | 102 | ], |
| 103 | 103 | fn (): mixed => $this->tracer->trace( |
| 104 | - name: 'Controller [' . $controller . ':' . $action . ']', |
|
| 104 | + name: 'Controller ['.$controller.':'.$action.']', |
|
| 105 | 105 | callback: fn (): mixed => $this->core->callAction( |
| 106 | 106 | controller: $controller, |
| 107 | 107 | action: $action, |
@@ -114,22 +114,22 @@ discard block |
||
| 114 | 114 | ] |
| 115 | 115 | ) |
| 116 | 116 | ); |
| 117 | - } catch (ControllerException $e) { |
|
| 117 | + }catch (ControllerException $e){ |
|
| 118 | 118 | \ob_get_clean(); |
| 119 | 119 | throw $this->mapException($e); |
| 120 | - } catch (\Throwable $e) { |
|
| 120 | + }catch (\Throwable $e){ |
|
| 121 | 121 | \ob_get_clean(); |
| 122 | 122 | throw $e; |
| 123 | - } finally { |
|
| 124 | - while (\ob_get_level() > $outputLevel + 1) { |
|
| 125 | - $output = \ob_get_clean() . $output; |
|
| 123 | + }finally{ |
|
| 124 | + while (\ob_get_level() > $outputLevel + 1){ |
|
| 125 | + $output = \ob_get_clean().$output; |
|
| 126 | 126 | } |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | return $this->wrapResponse( |
| 130 | 130 | $response, |
| 131 | 131 | $result, |
| 132 | - \ob_get_clean() . $output, |
|
| 132 | + \ob_get_clean().$output, |
|
| 133 | 133 | ); |
| 134 | 134 | } |
| 135 | 135 | |
@@ -142,21 +142,21 @@ discard block |
||
| 142 | 142 | */ |
| 143 | 143 | private function wrapResponse(Response $response, mixed $result = null, string $output = ''): Response |
| 144 | 144 | { |
| 145 | - if ($result instanceof Response) { |
|
| 146 | - if ($output !== '' && $result->getBody()->isWritable()) { |
|
| 145 | + if ($result instanceof Response){ |
|
| 146 | + if ($output !== '' && $result->getBody()->isWritable()){ |
|
| 147 | 147 | $result->getBody()->write($output); |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | return $result; |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | - if ($result instanceof \Generator) { |
|
| 153 | + if ($result instanceof \Generator){ |
|
| 154 | 154 | return $response->withBody(new GeneratorStream($result)); |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | - if (\is_array($result) || $result instanceof \JsonSerializable) { |
|
| 157 | + if (\is_array($result) || $result instanceof \JsonSerializable){ |
|
| 158 | 158 | $response = $this->writeJson($response, $result); |
| 159 | - } else { |
|
| 159 | + }else{ |
|
| 160 | 160 | $response->getBody()->write((string)$result); |
| 161 | 161 | } |
| 162 | 162 | |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | */ |
| 189 | 189 | private function checkValues(): void |
| 190 | 190 | { |
| 191 | - if ($this->controller === null) { |
|
| 191 | + if ($this->controller === null){ |
|
| 192 | 192 | throw new HandlerException('Controller and action pair are not set.'); |
| 193 | 193 | } |
| 194 | 194 | } |
@@ -89,7 +89,8 @@ discard block |
||
| 89 | 89 | $output = ''; |
| 90 | 90 | |
| 91 | 91 | $response = $this->responseFactory->createResponse(200); |
| 92 | - try { |
|
| 92 | + try |
|
| 93 | + { |
|
| 93 | 94 | $action = $this->verbActions |
| 94 | 95 | ? \strtolower($request->getMethod()) . \ucfirst($this->action) |
| 95 | 96 | : $this->action; |
@@ -114,14 +115,21 @@ discard block |
||
| 114 | 115 | ] |
| 115 | 116 | ) |
| 116 | 117 | ); |
| 117 | - } catch (ControllerException $e) { |
|
| 118 | + } |
|
| 119 | + catch (ControllerException $e) |
|
| 120 | + { |
|
| 118 | 121 | \ob_get_clean(); |
| 119 | 122 | throw $this->mapException($e); |
| 120 | - } catch (\Throwable $e) { |
|
| 123 | + } |
|
| 124 | + catch (\Throwable $e) |
|
| 125 | + { |
|
| 121 | 126 | \ob_get_clean(); |
| 122 | 127 | throw $e; |
| 123 | - } finally { |
|
| 124 | - while (\ob_get_level() > $outputLevel + 1) { |
|
| 128 | + } |
|
| 129 | + finally |
|
| 130 | + { |
|
| 131 | + while (\ob_get_level() > $outputLevel + 1) |
|
| 132 | + { |
|
| 125 | 133 | $output = \ob_get_clean() . $output; |
| 126 | 134 | } |
| 127 | 135 | } |
@@ -142,21 +150,27 @@ discard block |
||
| 142 | 150 | */ |
| 143 | 151 | private function wrapResponse(Response $response, mixed $result = null, string $output = ''): Response |
| 144 | 152 | { |
| 145 | - if ($result instanceof Response) { |
|
| 146 | - if ($output !== '' && $result->getBody()->isWritable()) { |
|
| 153 | + if ($result instanceof Response) |
|
| 154 | + { |
|
| 155 | + if ($output !== '' && $result->getBody()->isWritable()) |
|
| 156 | + { |
|
| 147 | 157 | $result->getBody()->write($output); |
| 148 | 158 | } |
| 149 | 159 | |
| 150 | 160 | return $result; |
| 151 | 161 | } |
| 152 | 162 | |
| 153 | - if ($result instanceof \Generator) { |
|
| 163 | + if ($result instanceof \Generator) |
|
| 164 | + { |
|
| 154 | 165 | return $response->withBody(new GeneratorStream($result)); |
| 155 | 166 | } |
| 156 | 167 | |
| 157 | - if (\is_array($result) || $result instanceof \JsonSerializable) { |
|
| 168 | + if (\is_array($result) || $result instanceof \JsonSerializable) |
|
| 169 | + { |
|
| 158 | 170 | $response = $this->writeJson($response, $result); |
| 159 | - } else { |
|
| 171 | + } |
|
| 172 | + else |
|
| 173 | + { |
|
| 160 | 174 | $response->getBody()->write((string)$result); |
| 161 | 175 | } |
| 162 | 176 | |
@@ -188,7 +202,8 @@ discard block |
||
| 188 | 202 | */ |
| 189 | 203 | private function checkValues(): void |
| 190 | 204 | { |
| 191 | - if ($this->controller === null) { |
|
| 205 | + if ($this->controller === null) |
|
| 206 | + { |
|
| 192 | 207 | throw new HandlerException('Controller and action pair are not set.'); |
| 193 | 208 | } |
| 194 | 209 | } |