@@ -51,21 +51,21 @@ discard block |
||
| 51 | 51 | $output = $result = null; |
| 52 | 52 | |
| 53 | 53 | $response = $this->responseFactory->createResponse(200); |
| 54 | - try { |
|
| 54 | + try{ |
|
| 55 | 55 | $result = ($this->callable)($request, $response); |
| 56 | - } catch (\Throwable $e) { |
|
| 56 | + }catch (\Throwable $e){ |
|
| 57 | 57 | ob_get_clean(); |
| 58 | 58 | throw $e; |
| 59 | - } finally { |
|
| 60 | - while (ob_get_level() > $outputLevel + 1) { |
|
| 61 | - $output = ob_get_clean() . $output; |
|
| 59 | + }finally{ |
|
| 60 | + while (ob_get_level() > $outputLevel + 1){ |
|
| 61 | + $output = ob_get_clean().$output; |
|
| 62 | 62 | } |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | return $this->wrapResponse( |
| 66 | 66 | $response, |
| 67 | 67 | $result, |
| 68 | - ob_get_clean() . $output |
|
| 68 | + ob_get_clean().$output |
|
| 69 | 69 | ); |
| 70 | 70 | } |
| 71 | 71 | |
@@ -80,17 +80,17 @@ discard block |
||
| 80 | 80 | */ |
| 81 | 81 | private function wrapResponse(Response $response, $result = null, string $output = ''): Response |
| 82 | 82 | { |
| 83 | - if ($result instanceof Response) { |
|
| 84 | - if (!empty($output) && $result->getBody()->isWritable()) { |
|
| 83 | + if ($result instanceof Response){ |
|
| 84 | + if (!empty($output) && $result->getBody()->isWritable()){ |
|
| 85 | 85 | $result->getBody()->write($output); |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | return $result; |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - if (is_array($result) || $result instanceof \JsonSerializable) { |
|
| 91 | + if (is_array($result) || $result instanceof \JsonSerializable){ |
|
| 92 | 92 | $response = $this->writeJson($response, $result); |
| 93 | - } else { |
|
| 93 | + }else{ |
|
| 94 | 94 | $response->getBody()->write((string)$result); |
| 95 | 95 | } |
| 96 | 96 | |
@@ -51,13 +51,19 @@ discard block |
||
| 51 | 51 | $output = $result = null; |
| 52 | 52 | |
| 53 | 53 | $response = $this->responseFactory->createResponse(200); |
| 54 | - try { |
|
| 54 | + try |
|
| 55 | + { |
|
| 55 | 56 | $result = ($this->callable)($request, $response); |
| 56 | - } catch (\Throwable $e) { |
|
| 57 | + } |
|
| 58 | + catch (\Throwable $e) |
|
| 59 | + { |
|
| 57 | 60 | ob_get_clean(); |
| 58 | 61 | throw $e; |
| 59 | - } finally { |
|
| 60 | - while (ob_get_level() > $outputLevel + 1) { |
|
| 62 | + } |
|
| 63 | + finally |
|
| 64 | + { |
|
| 65 | + while (ob_get_level() > $outputLevel + 1) |
|
| 66 | + { |
|
| 61 | 67 | $output = ob_get_clean() . $output; |
| 62 | 68 | } |
| 63 | 69 | } |
@@ -80,17 +86,22 @@ discard block |
||
| 80 | 86 | */ |
| 81 | 87 | private function wrapResponse(Response $response, $result = null, string $output = ''): Response |
| 82 | 88 | { |
| 83 | - if ($result instanceof Response) { |
|
| 84 | - if (!empty($output) && $result->getBody()->isWritable()) { |
|
| 89 | + if ($result instanceof Response) |
|
| 90 | + { |
|
| 91 | + if (!empty($output) && $result->getBody()->isWritable()) |
|
| 92 | + { |
|
| 85 | 93 | $result->getBody()->write($output); |
| 86 | 94 | } |
| 87 | 95 | |
| 88 | 96 | return $result; |
| 89 | 97 | } |
| 90 | 98 | |
| 91 | - if (is_array($result) || $result instanceof \JsonSerializable) { |
|
| 99 | + if (is_array($result) || $result instanceof \JsonSerializable) |
|
| 100 | + { |
|
| 92 | 101 | $response = $this->writeJson($response, $result); |
| 93 | - } else { |
|
| 102 | + } |
|
| 103 | + else |
|
| 104 | + { |
|
| 94 | 105 | $response->getBody()->write((string)$result); |
| 95 | 106 | } |
| 96 | 107 | |
@@ -47,13 +47,13 @@ discard block |
||
| 47 | 47 | Pipeline $pipeline, |
| 48 | 48 | ResponseFactoryInterface $responseFactory, |
| 49 | 49 | ContainerInterface $container |
| 50 | - ) { |
|
| 50 | + ){ |
|
| 51 | 51 | $this->config = $config; |
| 52 | 52 | $this->pipeline = $pipeline; |
| 53 | 53 | $this->responseFactory = $responseFactory; |
| 54 | 54 | $this->container = $container; |
| 55 | 55 | |
| 56 | - foreach ($this->config->getMiddleware() as $middleware) { |
|
| 56 | + foreach ($this->config->getMiddleware() as $middleware){ |
|
| 57 | 57 | $this->pipeline->pushMiddleware($this->container->get($middleware)); |
| 58 | 58 | } |
| 59 | 59 | } |
@@ -72,11 +72,11 @@ discard block |
||
| 72 | 72 | */ |
| 73 | 73 | public function setHandler($handler): self |
| 74 | 74 | { |
| 75 | - if ($handler instanceof RequestHandlerInterface) { |
|
| 75 | + if ($handler instanceof RequestHandlerInterface){ |
|
| 76 | 76 | $this->handler = $handler; |
| 77 | - } elseif (is_callable($handler)) { |
|
| 77 | + } elseif (is_callable($handler)){ |
|
| 78 | 78 | $this->handler = new CallableHandler($handler, $this->responseFactory); |
| 79 | - } else { |
|
| 79 | + }else{ |
|
| 80 | 80 | throw new HttpException( |
| 81 | 81 | 'Invalid handler is given, expects callable or RequestHandlerInterface.' |
| 82 | 82 | ); |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | */ |
| 94 | 94 | public function handle(ServerRequestInterface $request): ResponseInterface |
| 95 | 95 | { |
| 96 | - if (empty($this->handler)) { |
|
| 96 | + if (empty($this->handler)){ |
|
| 97 | 97 | throw new HttpException('Unable to run HttpCore, no handler is set.'); |
| 98 | 98 | } |
| 99 | 99 | |
@@ -53,7 +53,8 @@ discard block |
||
| 53 | 53 | $this->responseFactory = $responseFactory; |
| 54 | 54 | $this->container = $container; |
| 55 | 55 | |
| 56 | - foreach ($this->config->getMiddleware() as $middleware) { |
|
| 56 | + foreach ($this->config->getMiddleware() as $middleware) |
|
| 57 | + { |
|
| 57 | 58 | $this->pipeline->pushMiddleware($this->container->get($middleware)); |
| 58 | 59 | } |
| 59 | 60 | } |
@@ -72,11 +73,16 @@ discard block |
||
| 72 | 73 | */ |
| 73 | 74 | public function setHandler($handler): self |
| 74 | 75 | { |
| 75 | - if ($handler instanceof RequestHandlerInterface) { |
|
| 76 | + if ($handler instanceof RequestHandlerInterface) |
|
| 77 | + { |
|
| 76 | 78 | $this->handler = $handler; |
| 77 | - } elseif (is_callable($handler)) { |
|
| 79 | + } |
|
| 80 | + elseif (is_callable($handler)) |
|
| 81 | + { |
|
| 78 | 82 | $this->handler = new CallableHandler($handler, $this->responseFactory); |
| 79 | - } else { |
|
| 83 | + } |
|
| 84 | + else |
|
| 85 | + { |
|
| 80 | 86 | throw new HttpException( |
| 81 | 87 | 'Invalid handler is given, expects callable or RequestHandlerInterface.' |
| 82 | 88 | ); |
@@ -93,7 +99,8 @@ discard block |
||
| 93 | 99 | */ |
| 94 | 100 | public function handle(ServerRequestInterface $request): ResponseInterface |
| 95 | 101 | { |
| 96 | - if (empty($this->handler)) { |
|
| 102 | + if (empty($this->handler)) |
|
| 103 | + { |
|
| 97 | 104 | throw new HttpException('Unable to run HttpCore, no handler is set.'); |
| 98 | 105 | } |
| 99 | 106 | |
@@ -67,11 +67,11 @@ discard block |
||
| 67 | 67 | */ |
| 68 | 68 | private function assertNoPreviousOutput(): void |
| 69 | 69 | { |
| 70 | - if (headers_sent()) { |
|
| 70 | + if (headers_sent()){ |
|
| 71 | 71 | throw new EmitterException('Unable to emit response, headers already send.'); |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - if (ob_get_level() > 0 && ob_get_length() > 0) { |
|
| 74 | + if (ob_get_level() > 0 && ob_get_length() > 0){ |
|
| 75 | 75 | throw new EmitterException('Unable to emit response, found non closed buffered output.'); |
| 76 | 76 | } |
| 77 | 77 | } |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | 'HTTP/%s %d%s', |
| 98 | 98 | $response->getProtocolVersion(), |
| 99 | 99 | $statusCode, |
| 100 | - ($reasonPhrase ? ' ' . $reasonPhrase : '') |
|
| 100 | + ($reasonPhrase ? ' '.$reasonPhrase : '') |
|
| 101 | 101 | ), true, $statusCode); |
| 102 | 102 | } |
| 103 | 103 | |
@@ -115,10 +115,10 @@ discard block |
||
| 115 | 115 | { |
| 116 | 116 | $statusCode = $response->getStatusCode(); |
| 117 | 117 | |
| 118 | - foreach ($response->getHeaders() as $header => $values) { |
|
| 118 | + foreach ($response->getHeaders() as $header => $values){ |
|
| 119 | 119 | $name = $this->filterHeader($header); |
| 120 | 120 | $first = $name === 'Set-Cookie' ? false : true; |
| 121 | - foreach ($values as $value) { |
|
| 121 | + foreach ($values as $value){ |
|
| 122 | 122 | header(sprintf( |
| 123 | 123 | '%s: %s', |
| 124 | 124 | $name, |
@@ -67,11 +67,13 @@ discard block |
||
| 67 | 67 | */ |
| 68 | 68 | private function assertNoPreviousOutput(): void |
| 69 | 69 | { |
| 70 | - if (headers_sent()) { |
|
| 70 | + if (headers_sent()) |
|
| 71 | + { |
|
| 71 | 72 | throw new EmitterException('Unable to emit response, headers already send.'); |
| 72 | 73 | } |
| 73 | 74 | |
| 74 | - if (ob_get_level() > 0 && ob_get_length() > 0) { |
|
| 75 | + if (ob_get_level() > 0 && ob_get_length() > 0) |
|
| 76 | + { |
|
| 75 | 77 | throw new EmitterException('Unable to emit response, found non closed buffered output.'); |
| 76 | 78 | } |
| 77 | 79 | } |
@@ -115,10 +117,12 @@ discard block |
||
| 115 | 117 | { |
| 116 | 118 | $statusCode = $response->getStatusCode(); |
| 117 | 119 | |
| 118 | - foreach ($response->getHeaders() as $header => $values) { |
|
| 120 | + foreach ($response->getHeaders() as $header => $values) |
|
| 121 | + { |
|
| 119 | 122 | $name = $this->filterHeader($header); |
| 120 | 123 | $first = $name === 'Set-Cookie' ? false : true; |
| 121 | - foreach ($values as $value) { |
|
| 124 | + foreach ($values as $value) |
|
| 125 | + { |
|
| 122 | 126 | header(sprintf( |
| 123 | 127 | '%s: %s', |
| 124 | 128 | $name, |
@@ -73,12 +73,12 @@ |
||
| 73 | 73 | */ |
| 74 | 74 | public function handle(Request $request): Response |
| 75 | 75 | { |
| 76 | - if (empty($this->handler)) { |
|
| 76 | + if (empty($this->handler)){ |
|
| 77 | 77 | throw new PipelineException('Unable to run pipeline, no handler given.'); |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | $position = $this->position++; |
| 81 | - if (isset($this->middleware[$position])) { |
|
| 81 | + if (isset($this->middleware[$position])){ |
|
| 82 | 82 | return $this->middleware[$position]->process($request, $this); |
| 83 | 83 | } |
| 84 | 84 | |
@@ -73,16 +73,19 @@ |
||
| 73 | 73 | */ |
| 74 | 74 | public function handle(Request $request): Response |
| 75 | 75 | { |
| 76 | - if (empty($this->handler)) { |
|
| 76 | + if (empty($this->handler)) |
|
| 77 | + { |
|
| 77 | 78 | throw new PipelineException('Unable to run pipeline, no handler given.'); |
| 78 | 79 | } |
| 79 | 80 | |
| 80 | 81 | $position = $this->position++; |
| 81 | - if (isset($this->middleware[$position])) { |
|
| 82 | + if (isset($this->middleware[$position])) |
|
| 83 | + { |
|
| 82 | 84 | return $this->middleware[$position]->process($request, $this); |
| 83 | 85 | } |
| 84 | 86 | |
| 85 | - return $this->scope->runScope([Request::class => $request], function () use ($request) { |
|
| 87 | + return $this->scope->runScope([Request::class => $request], function () use ($request) |
|
| 88 | + { |
|
| 86 | 89 | return $this->handler->handle($request); |
| 87 | 90 | }); |
| 88 | 91 | } |
@@ -34,11 +34,11 @@ |
||
| 34 | 34 | */ |
| 35 | 35 | public function __construct(?int $code = null, string $message = '', ?\Throwable $previous = null) |
| 36 | 36 | { |
| 37 | - if (empty($code) && empty($this->code)) { |
|
| 37 | + if (empty($code) && empty($this->code)){ |
|
| 38 | 38 | $code = self::BAD_DATA; |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - if (empty($message)) { |
|
| 41 | + if (empty($message)){ |
|
| 42 | 42 | $message = "Http Error - {$code}"; |
| 43 | 43 | } |
| 44 | 44 | |
@@ -34,11 +34,13 @@ |
||
| 34 | 34 | */ |
| 35 | 35 | public function __construct(?int $code = null, string $message = '', ?\Throwable $previous = null) |
| 36 | 36 | { |
| 37 | - if (empty($code) && empty($this->code)) { |
|
| 37 | + if (empty($code) && empty($this->code)) |
|
| 38 | + { |
|
| 38 | 39 | $code = self::BAD_DATA; |
| 39 | 40 | } |
| 40 | 41 | |
| 41 | - if (empty($message)) { |
|
| 42 | + if (empty($message)) |
|
| 43 | + { |
|
| 42 | 44 | $message = "Http Error - {$code}"; |
| 43 | 45 | } |
| 44 | 46 | |
@@ -32,7 +32,7 @@ |
||
| 32 | 32 | */ |
| 33 | 33 | public function getFilename(string $name): ?string |
| 34 | 34 | { |
| 35 | - if (!empty($file = $this->get($name)) && !$file->getError()) { |
|
| 35 | + if (!empty($file = $this->get($name)) && !$file->getError()){ |
|
| 36 | 36 | return StreamWrapper::getFilename($file->getStream()); |
| 37 | 37 | } |
| 38 | 38 | |
@@ -32,7 +32,8 @@ |
||
| 32 | 32 | */ |
| 33 | 33 | public function getFilename(string $name): ?string |
| 34 | 34 | { |
| 35 | - if (!empty($file = $this->get($name)) && !$file->getError()) { |
|
| 35 | + if (!empty($file = $this->get($name)) && !$file->getError()) |
|
| 36 | + { |
|
| 36 | 37 | return StreamWrapper::getFilename($file->getStream()); |
| 37 | 38 | } |
| 38 | 39 | |
@@ -143,10 +143,10 @@ discard block |
||
| 143 | 143 | { |
| 144 | 144 | $input = clone $this; |
| 145 | 145 | |
| 146 | - if ($add) { |
|
| 147 | - $input->prefix .= '.' . $prefix; |
|
| 146 | + if ($add){ |
|
| 147 | + $input->prefix .= '.'.$prefix; |
|
| 148 | 148 | $input->prefix = trim($input->prefix, '.'); |
| 149 | - } else { |
|
| 149 | + }else{ |
|
| 150 | 150 | $input->prefix = $prefix; |
| 151 | 151 | } |
| 152 | 152 | |
@@ -162,12 +162,12 @@ discard block |
||
| 162 | 162 | { |
| 163 | 163 | $path = $this->uri()->getPath(); |
| 164 | 164 | |
| 165 | - if (empty($path)) { |
|
| 165 | + if (empty($path)){ |
|
| 166 | 166 | return '/'; |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | - if ($path[0] !== '/') { |
|
| 170 | - return '/' . $path; |
|
| 169 | + if ($path[0] !== '/'){ |
|
| 170 | + return '/'.$path; |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | return $path; |
@@ -192,9 +192,9 @@ discard block |
||
| 192 | 192 | */ |
| 193 | 193 | public function request(): Request |
| 194 | 194 | { |
| 195 | - try { |
|
| 195 | + try{ |
|
| 196 | 196 | $request = $this->container->get(Request::class); |
| 197 | - } catch (ContainerExceptionInterface $e) { |
|
| 197 | + }catch (ContainerExceptionInterface $e){ |
|
| 198 | 198 | throw new ScopeException( |
| 199 | 199 | 'Unable to get `ServerRequestInterface` in active container scope', |
| 200 | 200 | $e->getCode(), |
@@ -203,7 +203,7 @@ discard block |
||
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | //Flushing input state |
| 206 | - if ($this->request !== $request) { |
|
| 206 | + if ($this->request !== $request){ |
|
| 207 | 207 | $this->bags = []; |
| 208 | 208 | $this->request = $request; |
| 209 | 209 | } |
@@ -265,16 +265,16 @@ discard block |
||
| 265 | 265 | public function isJsonExpected(bool $softMatch = false): bool |
| 266 | 266 | { |
| 267 | 267 | $acceptHeader = AcceptHeader::fromString($this->request()->getHeaderLine('Accept')); |
| 268 | - foreach ($this->jsonTypes as $jsonType) { |
|
| 269 | - if ($acceptHeader->has($jsonType)) { |
|
| 268 | + foreach ($this->jsonTypes as $jsonType){ |
|
| 269 | + if ($acceptHeader->has($jsonType)){ |
|
| 270 | 270 | return true; |
| 271 | 271 | } |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | - if ($softMatch) { |
|
| 275 | - foreach ($acceptHeader->getAll() as $item) { |
|
| 274 | + if ($softMatch){ |
|
| 275 | + foreach ($acceptHeader->getAll() as $item){ |
|
| 276 | 276 | $itemValue = strtolower($item->getValue()); |
| 277 | - if (str_ends_with($itemValue, '/json') || str_ends_with($itemValue, '+json')) { |
|
| 277 | + if (str_ends_with($itemValue, '/json') || str_ends_with($itemValue, '+json')){ |
|
| 278 | 278 | return true; |
| 279 | 279 | } |
| 280 | 280 | } |
@@ -321,18 +321,18 @@ discard block |
||
| 321 | 321 | // ensure proper request association |
| 322 | 322 | $this->request(); |
| 323 | 323 | |
| 324 | - if (isset($this->bags[$name])) { |
|
| 324 | + if (isset($this->bags[$name])){ |
|
| 325 | 325 | return $this->bags[$name]; |
| 326 | 326 | } |
| 327 | 327 | |
| 328 | - if (!isset($this->bagAssociations[$name])) { |
|
| 328 | + if (!isset($this->bagAssociations[$name])){ |
|
| 329 | 329 | throw new InputException("Undefined input bag '{$name}'"); |
| 330 | 330 | } |
| 331 | 331 | |
| 332 | 332 | $class = $this->bagAssociations[$name]['class']; |
| 333 | 333 | $data = call_user_func([$this->request(), $this->bagAssociations[$name]['source']]); |
| 334 | 334 | |
| 335 | - if (!is_array($data)) { |
|
| 335 | + if (!is_array($data)){ |
|
| 336 | 336 | $data = (array)$data; |
| 337 | 337 | } |
| 338 | 338 | |
@@ -143,10 +143,13 @@ discard block |
||
| 143 | 143 | { |
| 144 | 144 | $input = clone $this; |
| 145 | 145 | |
| 146 | - if ($add) { |
|
| 146 | + if ($add) |
|
| 147 | + { |
|
| 147 | 148 | $input->prefix .= '.' . $prefix; |
| 148 | 149 | $input->prefix = trim($input->prefix, '.'); |
| 149 | - } else { |
|
| 150 | + } |
|
| 151 | + else |
|
| 152 | + { |
|
| 150 | 153 | $input->prefix = $prefix; |
| 151 | 154 | } |
| 152 | 155 | |
@@ -162,11 +165,13 @@ discard block |
||
| 162 | 165 | { |
| 163 | 166 | $path = $this->uri()->getPath(); |
| 164 | 167 | |
| 165 | - if (empty($path)) { |
|
| 168 | + if (empty($path)) |
|
| 169 | + { |
|
| 166 | 170 | return '/'; |
| 167 | 171 | } |
| 168 | 172 | |
| 169 | - if ($path[0] !== '/') { |
|
| 173 | + if ($path[0] !== '/') |
|
| 174 | + { |
|
| 170 | 175 | return '/' . $path; |
| 171 | 176 | } |
| 172 | 177 | |
@@ -192,9 +197,12 @@ discard block |
||
| 192 | 197 | */ |
| 193 | 198 | public function request(): Request |
| 194 | 199 | { |
| 195 | - try { |
|
| 200 | + try |
|
| 201 | + { |
|
| 196 | 202 | $request = $this->container->get(Request::class); |
| 197 | - } catch (ContainerExceptionInterface $e) { |
|
| 203 | + } |
|
| 204 | + catch (ContainerExceptionInterface $e) |
|
| 205 | + { |
|
| 198 | 206 | throw new ScopeException( |
| 199 | 207 | 'Unable to get `ServerRequestInterface` in active container scope', |
| 200 | 208 | $e->getCode(), |
@@ -203,7 +211,8 @@ discard block |
||
| 203 | 211 | } |
| 204 | 212 | |
| 205 | 213 | //Flushing input state |
| 206 | - if ($this->request !== $request) { |
|
| 214 | + if ($this->request !== $request) |
|
| 215 | + { |
|
| 207 | 216 | $this->bags = []; |
| 208 | 217 | $this->request = $request; |
| 209 | 218 | } |
@@ -265,16 +274,21 @@ discard block |
||
| 265 | 274 | public function isJsonExpected(bool $softMatch = false): bool |
| 266 | 275 | { |
| 267 | 276 | $acceptHeader = AcceptHeader::fromString($this->request()->getHeaderLine('Accept')); |
| 268 | - foreach ($this->jsonTypes as $jsonType) { |
|
| 269 | - if ($acceptHeader->has($jsonType)) { |
|
| 277 | + foreach ($this->jsonTypes as $jsonType) |
|
| 278 | + { |
|
| 279 | + if ($acceptHeader->has($jsonType)) |
|
| 280 | + { |
|
| 270 | 281 | return true; |
| 271 | 282 | } |
| 272 | 283 | } |
| 273 | 284 | |
| 274 | - if ($softMatch) { |
|
| 275 | - foreach ($acceptHeader->getAll() as $item) { |
|
| 285 | + if ($softMatch) |
|
| 286 | + { |
|
| 287 | + foreach ($acceptHeader->getAll() as $item) |
|
| 288 | + { |
|
| 276 | 289 | $itemValue = strtolower($item->getValue()); |
| 277 | - if (str_ends_with($itemValue, '/json') || str_ends_with($itemValue, '+json')) { |
|
| 290 | + if (str_ends_with($itemValue, '/json') || str_ends_with($itemValue, '+json')) |
|
| 291 | + { |
|
| 278 | 292 | return true; |
| 279 | 293 | } |
| 280 | 294 | } |
@@ -321,18 +335,21 @@ discard block |
||
| 321 | 335 | // ensure proper request association |
| 322 | 336 | $this->request(); |
| 323 | 337 | |
| 324 | - if (isset($this->bags[$name])) { |
|
| 338 | + if (isset($this->bags[$name])) |
|
| 339 | + { |
|
| 325 | 340 | return $this->bags[$name]; |
| 326 | 341 | } |
| 327 | 342 | |
| 328 | - if (!isset($this->bagAssociations[$name])) { |
|
| 343 | + if (!isset($this->bagAssociations[$name])) |
|
| 344 | + { |
|
| 329 | 345 | throw new InputException("Undefined input bag '{$name}'"); |
| 330 | 346 | } |
| 331 | 347 | |
| 332 | 348 | $class = $this->bagAssociations[$name]['class']; |
| 333 | 349 | $data = call_user_func([$this->request(), $this->bagAssociations[$name]['source']]); |
| 334 | 350 | |
| 335 | - if (!is_array($data)) { |
|
| 351 | + if (!is_array($data)) |
|
| 352 | + { |
|
| 336 | 353 | $data = (array)$data; |
| 337 | 354 | } |
| 338 | 355 | |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | { |
| 38 | 38 | $value = parent::get($this->normalize($name), $default); |
| 39 | 39 | |
| 40 | - if (!empty($implode) && is_array($value)) { |
|
| 40 | + if (!empty($implode) && is_array($value)){ |
|
| 41 | 41 | return implode($implode, $value); |
| 42 | 42 | } |
| 43 | 43 | |
@@ -55,8 +55,8 @@ discard block |
||
| 55 | 55 | |
| 56 | 56 | $values = parent::fetch($keys, $fill, $filler); |
| 57 | 57 | |
| 58 | - if (!empty($implode)) { |
|
| 59 | - foreach ($values as &$value) { |
|
| 58 | + if (!empty($implode)){ |
|
| 59 | + foreach ($values as &$value){ |
|
| 60 | 60 | $value = implode($implode, $value); |
| 61 | 61 | unset($value); |
| 62 | 62 | } |
@@ -37,7 +37,8 @@ discard block |
||
| 37 | 37 | { |
| 38 | 38 | $value = parent::get($this->normalize($name), $default); |
| 39 | 39 | |
| 40 | - if (!empty($implode) && is_array($value)) { |
|
| 40 | + if (!empty($implode) && is_array($value)) |
|
| 41 | + { |
|
| 41 | 42 | return implode($implode, $value); |
| 42 | 43 | } |
| 43 | 44 | |
@@ -55,8 +56,10 @@ discard block |
||
| 55 | 56 | |
| 56 | 57 | $values = parent::fetch($keys, $fill, $filler); |
| 57 | 58 | |
| 58 | - if (!empty($implode)) { |
|
| 59 | - foreach ($values as &$value) { |
|
| 59 | + if (!empty($implode)) |
|
| 60 | + { |
|
| 61 | + foreach ($values as &$value) |
|
| 62 | + { |
|
| 60 | 63 | $value = implode($implode, $value); |
| 61 | 64 | unset($value); |
| 62 | 65 | } |
@@ -30,7 +30,6 @@ |
||
| 30 | 30 | * |
| 31 | 31 | * |
| 32 | 32 | * @param bool|string $implode Implode header lines, false to return header as array. |
| 33 | - |
|
| 34 | 33 | * @return string|array |
| 35 | 34 | */ |
| 36 | 35 | public function get(string $name, $default = null, $implode = ',') |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | ResponseFactoryInterface $responseFactory, |
| 47 | 47 | StreamFactoryInterface $streamFactory, |
| 48 | 48 | FilesInterface $files |
| 49 | - ) { |
|
| 49 | + ){ |
|
| 50 | 50 | $this->responseFactory = $responseFactory; |
| 51 | 51 | $this->streamFactory = $streamFactory; |
| 52 | 52 | $this->files = $files; |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | */ |
| 73 | 73 | public function redirect($uri, int $code = 302): ResponseInterface |
| 74 | 74 | { |
| 75 | - if (!is_string($uri) && !$uri instanceof UriInterface) { |
|
| 75 | + if (!is_string($uri) && !$uri instanceof UriInterface){ |
|
| 76 | 76 | throw new ResponseException('Redirect allowed only for string or UriInterface uris'); |
| 77 | 77 | } |
| 78 | 78 | |
@@ -108,8 +108,8 @@ discard block |
||
| 108 | 108 | string $name = '', |
| 109 | 109 | string $mime = 'application/octet-stream' |
| 110 | 110 | ): ResponseInterface { |
| 111 | - if (empty($name)) { |
|
| 112 | - if (!is_string($filename)) { |
|
| 111 | + if (empty($name)){ |
|
| 112 | + if (!is_string($filename)){ |
|
| 113 | 113 | throw new ResponseException('Unable to resolve public filename'); |
| 114 | 114 | } |
| 115 | 115 | |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | $response = $response->withHeader('Content-Length', (string)$stream->getSize()); |
| 124 | 124 | $response = $response->withHeader( |
| 125 | 125 | 'Content-Disposition', |
| 126 | - 'attachment; filename="' . addcslashes($name, '"') . '"' |
|
| 126 | + 'attachment; filename="'.addcslashes($name, '"').'"' |
|
| 127 | 127 | ); |
| 128 | 128 | |
| 129 | 129 | return $response->withBody($stream); |
@@ -156,19 +156,19 @@ discard block |
||
| 156 | 156 | */ |
| 157 | 157 | private function getStream($file): StreamInterface |
| 158 | 158 | { |
| 159 | - if ($file instanceof StreamableInterface) { |
|
| 159 | + if ($file instanceof StreamableInterface){ |
|
| 160 | 160 | return $file->getStream(); |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | - if ($file instanceof StreamInterface) { |
|
| 163 | + if ($file instanceof StreamInterface){ |
|
| 164 | 164 | return $file; |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | - if (is_resource($file)) { |
|
| 167 | + if (is_resource($file)){ |
|
| 168 | 168 | return $this->streamFactory->createStreamFromResource($file); |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | - if (!$this->files->isFile($file)) { |
|
| 171 | + if (!$this->files->isFile($file)){ |
|
| 172 | 172 | throw new ResponseException('Unable to allocate response body stream, file does not exist'); |
| 173 | 173 | } |
| 174 | 174 | |
@@ -72,7 +72,8 @@ discard block |
||
| 72 | 72 | */ |
| 73 | 73 | public function redirect($uri, int $code = 302): ResponseInterface |
| 74 | 74 | { |
| 75 | - if (!is_string($uri) && !$uri instanceof UriInterface) { |
|
| 75 | + if (!is_string($uri) && !$uri instanceof UriInterface) |
|
| 76 | + { |
|
| 76 | 77 | throw new ResponseException('Redirect allowed only for string or UriInterface uris'); |
| 77 | 78 | } |
| 78 | 79 | |
@@ -108,8 +109,10 @@ discard block |
||
| 108 | 109 | string $name = '', |
| 109 | 110 | string $mime = 'application/octet-stream' |
| 110 | 111 | ): ResponseInterface { |
| 111 | - if (empty($name)) { |
|
| 112 | - if (!is_string($filename)) { |
|
| 112 | + if (empty($name)) |
|
| 113 | + { |
|
| 114 | + if (!is_string($filename)) |
|
| 115 | + { |
|
| 113 | 116 | throw new ResponseException('Unable to resolve public filename'); |
| 114 | 117 | } |
| 115 | 118 | |
@@ -156,19 +159,23 @@ discard block |
||
| 156 | 159 | */ |
| 157 | 160 | private function getStream($file): StreamInterface |
| 158 | 161 | { |
| 159 | - if ($file instanceof StreamableInterface) { |
|
| 162 | + if ($file instanceof StreamableInterface) |
|
| 163 | + { |
|
| 160 | 164 | return $file->getStream(); |
| 161 | 165 | } |
| 162 | 166 | |
| 163 | - if ($file instanceof StreamInterface) { |
|
| 167 | + if ($file instanceof StreamInterface) |
|
| 168 | + { |
|
| 164 | 169 | return $file; |
| 165 | 170 | } |
| 166 | 171 | |
| 167 | - if (is_resource($file)) { |
|
| 172 | + if (is_resource($file)) |
|
| 173 | + { |
|
| 168 | 174 | return $this->streamFactory->createStreamFromResource($file); |
| 169 | 175 | } |
| 170 | 176 | |
| 171 | - if (!$this->files->isFile($file)) { |
|
| 177 | + if (!$this->files->isFile($file)) |
|
| 178 | + { |
|
| 172 | 179 | throw new ResponseException('Unable to allocate response body stream, file does not exist'); |
| 173 | 180 | } |
| 174 | 181 | |