@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | { |
| 45 | 45 | $core = $this->getCore(); |
| 46 | 46 | |
| 47 | - $core->setHandler(function () { |
|
| 47 | + $core->setHandler(function (){ |
|
| 48 | 48 | return 'hello world'; |
| 49 | 49 | }); |
| 50 | 50 | |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | public function testHandlerInterface(): void |
| 74 | 74 | { |
| 75 | 75 | $core = $this->getCore(); |
| 76 | - $core->setHandler(new CallableHandler(function () { |
|
| 76 | + $core->setHandler(new CallableHandler(function (){ |
|
| 77 | 77 | return 'hello world'; |
| 78 | 78 | }, new ResponseFactory(new HttpConfig(['headers' => []])))); |
| 79 | 79 | |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | { |
| 86 | 86 | $core = $this->getCore(); |
| 87 | 87 | |
| 88 | - $core->setHandler(function ($req, $resp) { |
|
| 88 | + $core->setHandler(function ($req, $resp){ |
|
| 89 | 89 | return $resp->withAddedHeader('hello', 'value'); |
| 90 | 90 | }); |
| 91 | 91 | |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | { |
| 99 | 99 | $core = $this->getCore(); |
| 100 | 100 | |
| 101 | - $core->setHandler(function ($req, $resp) { |
|
| 101 | + $core->setHandler(function ($req, $resp){ |
|
| 102 | 102 | echo 'hello!'; |
| 103 | 103 | |
| 104 | 104 | return $resp->withAddedHeader('hello', 'value'); |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | { |
| 115 | 115 | $core = $this->getCore(); |
| 116 | 116 | |
| 117 | - $core->setHandler(function ($req, $resp) { |
|
| 117 | + $core->setHandler(function ($req, $resp){ |
|
| 118 | 118 | echo 'hello!'; |
| 119 | 119 | $resp->getBody()->write('world '); |
| 120 | 120 | |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | { |
| 132 | 132 | $core = $this->getCore(); |
| 133 | 133 | |
| 134 | - $core->setHandler(function () { |
|
| 134 | + $core->setHandler(function (){ |
|
| 135 | 135 | ob_start(); |
| 136 | 136 | ob_start(); |
| 137 | 137 | echo 'hello!'; |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | { |
| 153 | 153 | $core = $this->getCore(); |
| 154 | 154 | |
| 155 | - $core->setHandler(function () { |
|
| 155 | + $core->setHandler(function (){ |
|
| 156 | 156 | return [ |
| 157 | 157 | 'status' => 404, |
| 158 | 158 | 'message' => 'not found', |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | { |
| 169 | 169 | $core = $this->getCore(); |
| 170 | 170 | |
| 171 | - $core->setHandler(function () { |
|
| 171 | + $core->setHandler(function (){ |
|
| 172 | 172 | return new Json([ |
| 173 | 173 | 'status' => 404, |
| 174 | 174 | 'message' => 'not found', |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | { |
| 185 | 185 | $core = $this->getCore([HeaderMiddleware::class]); |
| 186 | 186 | |
| 187 | - $core->setHandler(function () { |
|
| 187 | + $core->setHandler(function (){ |
|
| 188 | 188 | return 'hello?'; |
| 189 | 189 | }); |
| 190 | 190 | |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | $core->getPipeline()->pushMiddleware(new Header2Middleware()); |
| 202 | 202 | $core->getPipeline()->riseMiddleware(new HeaderMiddleware()); |
| 203 | 203 | |
| 204 | - $core->setHandler(function () { |
|
| 204 | + $core->setHandler(function (){ |
|
| 205 | 205 | return 'hello?'; |
| 206 | 206 | }); |
| 207 | 207 | |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | $core->getPipeline()->pushMiddleware(new HeaderMiddleware()); |
| 219 | 219 | $core->getPipeline()->riseMiddleware(new Header2Middleware()); |
| 220 | 220 | |
| 221 | - $core->setHandler(function () { |
|
| 221 | + $core->setHandler(function (){ |
|
| 222 | 222 | return 'hello?'; |
| 223 | 223 | }); |
| 224 | 224 | |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | { |
| 233 | 233 | $core = $this->getCore(); |
| 234 | 234 | |
| 235 | - $core->setHandler(function () { |
|
| 235 | + $core->setHandler(function (){ |
|
| 236 | 236 | $this->assertTrue($this->container->has(ServerRequestInterface::class)); |
| 237 | 237 | |
| 238 | 238 | return 'OK'; |
@@ -44,7 +44,8 @@ discard block |
||
| 44 | 44 | { |
| 45 | 45 | $core = $this->getCore(); |
| 46 | 46 | |
| 47 | - $core->setHandler(function () { |
|
| 47 | + $core->setHandler(function () |
|
| 48 | + { |
|
| 48 | 49 | return 'hello world'; |
| 49 | 50 | }); |
| 50 | 51 | |
@@ -73,7 +74,8 @@ discard block |
||
| 73 | 74 | public function testHandlerInterface(): void |
| 74 | 75 | { |
| 75 | 76 | $core = $this->getCore(); |
| 76 | - $core->setHandler(new CallableHandler(function () { |
|
| 77 | + $core->setHandler(new CallableHandler(function () |
|
| 78 | + { |
|
| 77 | 79 | return 'hello world'; |
| 78 | 80 | }, new ResponseFactory(new HttpConfig(['headers' => []])))); |
| 79 | 81 | |
@@ -85,7 +87,8 @@ discard block |
||
| 85 | 87 | { |
| 86 | 88 | $core = $this->getCore(); |
| 87 | 89 | |
| 88 | - $core->setHandler(function ($req, $resp) { |
|
| 90 | + $core->setHandler(function ($req, $resp) |
|
| 91 | + { |
|
| 89 | 92 | return $resp->withAddedHeader('hello', 'value'); |
| 90 | 93 | }); |
| 91 | 94 | |
@@ -98,7 +101,8 @@ discard block |
||
| 98 | 101 | { |
| 99 | 102 | $core = $this->getCore(); |
| 100 | 103 | |
| 101 | - $core->setHandler(function ($req, $resp) { |
|
| 104 | + $core->setHandler(function ($req, $resp) |
|
| 105 | + { |
|
| 102 | 106 | echo 'hello!'; |
| 103 | 107 | |
| 104 | 108 | return $resp->withAddedHeader('hello', 'value'); |
@@ -114,7 +118,8 @@ discard block |
||
| 114 | 118 | { |
| 115 | 119 | $core = $this->getCore(); |
| 116 | 120 | |
| 117 | - $core->setHandler(function ($req, $resp) { |
|
| 121 | + $core->setHandler(function ($req, $resp) |
|
| 122 | + { |
|
| 118 | 123 | echo 'hello!'; |
| 119 | 124 | $resp->getBody()->write('world '); |
| 120 | 125 | |
@@ -131,7 +136,8 @@ discard block |
||
| 131 | 136 | { |
| 132 | 137 | $core = $this->getCore(); |
| 133 | 138 | |
| 134 | - $core->setHandler(function () { |
|
| 139 | + $core->setHandler(function () |
|
| 140 | + { |
|
| 135 | 141 | ob_start(); |
| 136 | 142 | ob_start(); |
| 137 | 143 | echo 'hello!'; |
@@ -152,7 +158,8 @@ discard block |
||
| 152 | 158 | { |
| 153 | 159 | $core = $this->getCore(); |
| 154 | 160 | |
| 155 | - $core->setHandler(function () { |
|
| 161 | + $core->setHandler(function () |
|
| 162 | + { |
|
| 156 | 163 | return [ |
| 157 | 164 | 'status' => 404, |
| 158 | 165 | 'message' => 'not found', |
@@ -168,7 +175,8 @@ discard block |
||
| 168 | 175 | { |
| 169 | 176 | $core = $this->getCore(); |
| 170 | 177 | |
| 171 | - $core->setHandler(function () { |
|
| 178 | + $core->setHandler(function () |
|
| 179 | + { |
|
| 172 | 180 | return new Json([ |
| 173 | 181 | 'status' => 404, |
| 174 | 182 | 'message' => 'not found', |
@@ -184,7 +192,8 @@ discard block |
||
| 184 | 192 | { |
| 185 | 193 | $core = $this->getCore([HeaderMiddleware::class]); |
| 186 | 194 | |
| 187 | - $core->setHandler(function () { |
|
| 195 | + $core->setHandler(function () |
|
| 196 | + { |
|
| 188 | 197 | return 'hello?'; |
| 189 | 198 | }); |
| 190 | 199 | |
@@ -201,7 +210,8 @@ discard block |
||
| 201 | 210 | $core->getPipeline()->pushMiddleware(new Header2Middleware()); |
| 202 | 211 | $core->getPipeline()->riseMiddleware(new HeaderMiddleware()); |
| 203 | 212 | |
| 204 | - $core->setHandler(function () { |
|
| 213 | + $core->setHandler(function () |
|
| 214 | + { |
|
| 205 | 215 | return 'hello?'; |
| 206 | 216 | }); |
| 207 | 217 | |
@@ -218,7 +228,8 @@ discard block |
||
| 218 | 228 | $core->getPipeline()->pushMiddleware(new HeaderMiddleware()); |
| 219 | 229 | $core->getPipeline()->riseMiddleware(new Header2Middleware()); |
| 220 | 230 | |
| 221 | - $core->setHandler(function () { |
|
| 231 | + $core->setHandler(function () |
|
| 232 | + { |
|
| 222 | 233 | return 'hello?'; |
| 223 | 234 | }); |
| 224 | 235 | |
@@ -232,7 +243,8 @@ discard block |
||
| 232 | 243 | { |
| 233 | 244 | $core = $this->getCore(); |
| 234 | 245 | |
| 235 | - $core->setHandler(function () { |
|
| 246 | + $core->setHandler(function () |
|
| 247 | + { |
|
| 236 | 248 | $this->assertTrue($this->container->has(ServerRequestInterface::class)); |
| 237 | 249 | |
| 238 | 250 | return 'OK'; |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | { |
| 27 | 27 | $pipeline = new Pipeline(new Container()); |
| 28 | 28 | |
| 29 | - $handler = new CallableHandler(function () { |
|
| 29 | + $handler = new CallableHandler(function (){ |
|
| 30 | 30 | return 'response'; |
| 31 | 31 | }, new ResponseFactory(new HttpConfig(['headers' => []]))); |
| 32 | 32 | |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | { |
| 42 | 42 | $pipeline = new Pipeline(new Container()); |
| 43 | 43 | |
| 44 | - $handler = new CallableHandler(function () { |
|
| 44 | + $handler = new CallableHandler(function (){ |
|
| 45 | 45 | return 'response'; |
| 46 | 46 | }, new ResponseFactory(new HttpConfig(['headers' => []]))); |
| 47 | 47 | |
@@ -26,7 +26,8 @@ discard block |
||
| 26 | 26 | { |
| 27 | 27 | $pipeline = new Pipeline(new Container()); |
| 28 | 28 | |
| 29 | - $handler = new CallableHandler(function () { |
|
| 29 | + $handler = new CallableHandler(function () |
|
| 30 | + { |
|
| 30 | 31 | return 'response'; |
| 31 | 32 | }, new ResponseFactory(new HttpConfig(['headers' => []]))); |
| 32 | 33 | |
@@ -41,7 +42,8 @@ discard block |
||
| 41 | 42 | { |
| 42 | 43 | $pipeline = new Pipeline(new Container()); |
| 43 | 44 | |
| 44 | - $handler = new CallableHandler(function () { |
|
| 45 | + $handler = new CallableHandler(function () |
|
| 46 | + { |
|
| 45 | 47 | return 'response'; |
| 46 | 48 | }, new ResponseFactory(new HttpConfig(['headers' => []]))); |
| 47 | 49 | |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | public function emptyItemProvider(): iterable |
| 34 | 34 | { |
| 35 | 35 | $values = ['', ' ']; |
| 36 | - foreach ($values as $value) { |
|
| 36 | + foreach ($values as $value){ |
|
| 37 | 37 | yield from [ |
| 38 | 38 | [AcceptHeaderItem::fromString($value)], |
| 39 | 39 | [new AcceptHeaderItem($value)], |
@@ -82,11 +82,11 @@ discard block |
||
| 82 | 82 | */ |
| 83 | 83 | public function testItemQualityBoundaries(float $quality, AcceptHeaderItem $item): void |
| 84 | 84 | { |
| 85 | - if ($quality > 1) { |
|
| 85 | + if ($quality > 1){ |
|
| 86 | 86 | $this->assertSame(1.0, $item->getQuality()); |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - if ($quality < 0) { |
|
| 89 | + if ($quality < 0){ |
|
| 90 | 90 | $this->assertSame(0.0, $item->getQuality()); |
| 91 | 91 | } |
| 92 | 92 | |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | public function qualityBoundariesProvider(): iterable |
| 101 | 101 | { |
| 102 | 102 | $qualities = [-1, 0, 0.5, 1, 2]; |
| 103 | - foreach ($qualities as $quality) { |
|
| 103 | + foreach ($qualities as $quality){ |
|
| 104 | 104 | yield from [ |
| 105 | 105 | [$quality, AcceptHeaderItem::fromString("*;q=$quality")], |
| 106 | 106 | [$quality, AcceptHeaderItem::fromString("*;Q=$quality")], |
@@ -140,9 +140,9 @@ discard block |
||
| 140 | 140 | ] |
| 141 | 141 | ]; |
| 142 | 142 | |
| 143 | - foreach ($set as $params) { |
|
| 143 | + foreach ($set as $params){ |
|
| 144 | 144 | $formattedParams = []; |
| 145 | - foreach ($params['passed'] as $k => $v) { |
|
| 145 | + foreach ($params['passed'] as $k => $v){ |
|
| 146 | 146 | $formattedParams[] = "$k=$v"; |
| 147 | 147 | } |
| 148 | 148 | |
@@ -33,7 +33,8 @@ discard block |
||
| 33 | 33 | public function emptyItemProvider(): iterable |
| 34 | 34 | { |
| 35 | 35 | $values = ['', ' ']; |
| 36 | - foreach ($values as $value) { |
|
| 36 | + foreach ($values as $value) |
|
| 37 | + { |
|
| 37 | 38 | yield from [ |
| 38 | 39 | [AcceptHeaderItem::fromString($value)], |
| 39 | 40 | [new AcceptHeaderItem($value)], |
@@ -82,11 +83,13 @@ discard block |
||
| 82 | 83 | */ |
| 83 | 84 | public function testItemQualityBoundaries(float $quality, AcceptHeaderItem $item): void |
| 84 | 85 | { |
| 85 | - if ($quality > 1) { |
|
| 86 | + if ($quality > 1) |
|
| 87 | + { |
|
| 86 | 88 | $this->assertSame(1.0, $item->getQuality()); |
| 87 | 89 | } |
| 88 | 90 | |
| 89 | - if ($quality < 0) { |
|
| 91 | + if ($quality < 0) |
|
| 92 | + { |
|
| 90 | 93 | $this->assertSame(0.0, $item->getQuality()); |
| 91 | 94 | } |
| 92 | 95 | |
@@ -100,7 +103,8 @@ discard block |
||
| 100 | 103 | public function qualityBoundariesProvider(): iterable |
| 101 | 104 | { |
| 102 | 105 | $qualities = [-1, 0, 0.5, 1, 2]; |
| 103 | - foreach ($qualities as $quality) { |
|
| 106 | + foreach ($qualities as $quality) |
|
| 107 | + { |
|
| 104 | 108 | yield from [ |
| 105 | 109 | [$quality, AcceptHeaderItem::fromString("*;q=$quality")], |
| 106 | 110 | [$quality, AcceptHeaderItem::fromString("*;Q=$quality")], |
@@ -140,9 +144,11 @@ discard block |
||
| 140 | 144 | ] |
| 141 | 145 | ]; |
| 142 | 146 | |
| 143 | - foreach ($set as $params) { |
|
| 147 | + foreach ($set as $params) |
|
| 148 | + { |
|
| 144 | 149 | $formattedParams = []; |
| 145 | - foreach ($params['passed'] as $k => $v) { |
|
| 150 | + foreach ($params['passed'] as $k => $v) |
|
| 151 | + { |
|
| 146 | 152 | $formattedParams[] = "$k=$v"; |
| 147 | 153 | } |
| 148 | 154 | |
@@ -26,7 +26,7 @@ |
||
| 26 | 26 | string $clientFilename = null, |
| 27 | 27 | string $clientMediaType = null |
| 28 | 28 | ): UploadedFileInterface { |
| 29 | - if ($size === null) { |
|
| 29 | + if ($size === null){ |
|
| 30 | 30 | $size = $stream->getSize(); |
| 31 | 31 | } |
| 32 | 32 | |
@@ -26,7 +26,8 @@ |
||
| 26 | 26 | string $clientFilename = null, |
| 27 | 27 | string $clientMediaType = null |
| 28 | 28 | ): UploadedFileInterface { |
| 29 | - if ($size === null) { |
|
| 29 | + if ($size === null) |
|
| 30 | + { |
|
| 30 | 31 | $size = $stream->getSize(); |
| 31 | 32 | } |
| 32 | 33 | |
@@ -37,7 +37,7 @@ |
||
| 37 | 37 | $response = new Response('php://memory', $code, []); |
| 38 | 38 | $response = $response->withStatus($code, $reasonPhrase); |
| 39 | 39 | |
| 40 | - foreach ($this->config->getBaseHeaders() as $header => $value) { |
|
| 40 | + foreach ($this->config->getBaseHeaders() as $header => $value){ |
|
| 41 | 41 | $response = $response->withAddedHeader($header, $value); |
| 42 | 42 | } |
| 43 | 43 | |
@@ -37,7 +37,8 @@ |
||
| 37 | 37 | $response = new Response('php://memory', $code, []); |
| 38 | 38 | $response = $response->withStatus($code, $reasonPhrase); |
| 39 | 39 | |
| 40 | - foreach ($this->config->getBaseHeaders() as $header => $value) { |
|
| 40 | + foreach ($this->config->getBaseHeaders() as $header => $value) |
|
| 41 | + { |
|
| 41 | 42 | $response = $response->withAddedHeader($header, $value); |
| 42 | 43 | } |
| 43 | 44 | |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | $this->container->bind(ServerRequestInterface::class, $request); |
| 165 | 165 | |
| 166 | 166 | $this->assertSame( |
| 167 | - ['PATH' => 'sample',], |
|
| 167 | + ['PATH' => 'sample', ], |
|
| 168 | 168 | $this->input->server->__debugInfo() |
| 169 | 169 | ); |
| 170 | 170 | } |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | $this->container->bind(ServerRequestInterface::class, $request); |
| 179 | 179 | |
| 180 | 180 | $this->assertSame( |
| 181 | - ['PATH' => 'sample',], |
|
| 181 | + ['PATH' => 'sample', ], |
|
| 182 | 182 | iterator_to_array($this->input->server) |
| 183 | 183 | ); |
| 184 | 184 | } |
@@ -75,7 +75,6 @@ |
||
| 75 | 75 | * @param Response $response Initial pipeline response. |
| 76 | 76 | * @param mixed $result Generated endpoint output. |
| 77 | 77 | * @param string $output Buffer output. |
| 78 | - |
|
| 79 | 78 | * @return Response |
| 80 | 79 | */ |
| 81 | 80 | private function wrapResponse(Response $response, $result = null, string $output = ''): Response |
@@ -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 | |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | */ |
| 37 | 37 | public function __construct(array $items = []) |
| 38 | 38 | { |
| 39 | - foreach ($items as $item) { |
|
| 39 | + foreach ($items as $item){ |
|
| 40 | 40 | $this->addItem($item); |
| 41 | 41 | } |
| 42 | 42 | } |
@@ -58,9 +58,9 @@ discard block |
||
| 58 | 58 | $header = new static(); |
| 59 | 59 | |
| 60 | 60 | $parts = explode(',', $raw); |
| 61 | - foreach ($parts as $part) { |
|
| 61 | + foreach ($parts as $part){ |
|
| 62 | 62 | $part = trim($part); |
| 63 | - if ($part !== '') { |
|
| 63 | + if ($part !== ''){ |
|
| 64 | 64 | $header->addItem($part); |
| 65 | 65 | } |
| 66 | 66 | } |
@@ -103,11 +103,11 @@ discard block |
||
| 103 | 103 | */ |
| 104 | 104 | public function getAll(): array |
| 105 | 105 | { |
| 106 | - if (!$this->sorted) { |
|
| 106 | + if (!$this->sorted){ |
|
| 107 | 107 | /** |
| 108 | 108 | * Sort item in descending order. |
| 109 | 109 | */ |
| 110 | - uasort($this->items, static function (AcceptHeaderItem $a, AcceptHeaderItem $b) { |
|
| 110 | + uasort($this->items, static function (AcceptHeaderItem $a, AcceptHeaderItem $b){ |
|
| 111 | 111 | return self::compare($a, $b) * -1; |
| 112 | 112 | }); |
| 113 | 113 | |
@@ -124,11 +124,11 @@ discard block |
||
| 124 | 124 | */ |
| 125 | 125 | private function addItem($item): void |
| 126 | 126 | { |
| 127 | - if (is_scalar($item)) { |
|
| 127 | + if (is_scalar($item)){ |
|
| 128 | 128 | $item = AcceptHeaderItem::fromString((string)$item); |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | - if (!$item instanceof AcceptHeaderItem) { |
|
| 131 | + if (!$item instanceof AcceptHeaderItem){ |
|
| 132 | 132 | throw new AcceptHeaderException(sprintf( |
| 133 | 133 | 'Accept Header item expected to be an instance of `%s` or a string, got `%s`', |
| 134 | 134 | AcceptHeaderItem::class, |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | $value = strtolower($item->getValue()); |
| 140 | - if ($value !== '' && (!$this->has($value) || self::compare($item, $this->get($value)) === 1)) { |
|
| 140 | + if ($value !== '' && (!$this->has($value) || self::compare($item, $this->get($value)) === 1)){ |
|
| 141 | 141 | $this->sorted = false; |
| 142 | 142 | $this->items[$value] = $item; |
| 143 | 143 | } |
@@ -153,9 +153,9 @@ discard block |
||
| 153 | 153 | */ |
| 154 | 154 | private static function compare(AcceptHeaderItem $a, AcceptHeaderItem $b): int |
| 155 | 155 | { |
| 156 | - if ($a->getQuality() === $b->getQuality()) { |
|
| 156 | + if ($a->getQuality() === $b->getQuality()){ |
|
| 157 | 157 | // If quality are same value with more params has more weight. |
| 158 | - if (count($a->getParams()) === count($b->getParams())) { |
|
| 158 | + if (count($a->getParams()) === count($b->getParams())){ |
|
| 159 | 159 | // If quality and params then check for specific type or subtype. |
| 160 | 160 | // Means */* or * has less weight. |
| 161 | 161 | return static::compareValue($a->getValue(), $b->getValue()); |
@@ -178,11 +178,11 @@ discard block |
||
| 178 | 178 | private static function compareValue(string $a, string $b): int |
| 179 | 179 | { |
| 180 | 180 | // Check "Accept" headers values with it is type and subtype. |
| 181 | - if (strpos($a, '/') !== false && strpos($b, '/') !== false) { |
|
| 181 | + if (strpos($a, '/') !== false && strpos($b, '/') !== false){ |
|
| 182 | 182 | [$typeA, $subtypeA] = explode('/', $a, 2); |
| 183 | 183 | [$typeB, $subtypeB] = explode('/', $b, 2); |
| 184 | 184 | |
| 185 | - if ($typeA === $typeB) { |
|
| 185 | + if ($typeA === $typeB){ |
|
| 186 | 186 | return static::compareAtomic($subtypeA, $subtypeB); |
| 187 | 187 | } |
| 188 | 188 | |
@@ -199,23 +199,23 @@ discard block |
||
| 199 | 199 | */ |
| 200 | 200 | private static function compareAtomic(string $a, string $b): int |
| 201 | 201 | { |
| 202 | - if (mb_strpos($a, '*/') === 0) { |
|
| 202 | + if (mb_strpos($a, '*/') === 0){ |
|
| 203 | 203 | $a = '*'; |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | - if (mb_strpos($b, '*/') === 0) { |
|
| 206 | + if (mb_strpos($b, '*/') === 0){ |
|
| 207 | 207 | $b = '*'; |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | - if (strtolower($a) === strtolower($b)) { |
|
| 210 | + if (strtolower($a) === strtolower($b)){ |
|
| 211 | 211 | return 0; |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | - if ($a === '*') { |
|
| 214 | + if ($a === '*'){ |
|
| 215 | 215 | return -1; |
| 216 | 216 | } |
| 217 | 217 | |
| 218 | - if ($b === '*') { |
|
| 218 | + if ($b === '*'){ |
|
| 219 | 219 | return 1; |
| 220 | 220 | } |
| 221 | 221 | |
@@ -36,7 +36,8 @@ discard block |
||
| 36 | 36 | */ |
| 37 | 37 | public function __construct(array $items = []) |
| 38 | 38 | { |
| 39 | - foreach ($items as $item) { |
|
| 39 | + foreach ($items as $item) |
|
| 40 | + { |
|
| 40 | 41 | $this->addItem($item); |
| 41 | 42 | } |
| 42 | 43 | } |
@@ -58,9 +59,11 @@ discard block |
||
| 58 | 59 | $header = new static(); |
| 59 | 60 | |
| 60 | 61 | $parts = explode(',', $raw); |
| 61 | - foreach ($parts as $part) { |
|
| 62 | + foreach ($parts as $part) |
|
| 63 | + { |
|
| 62 | 64 | $part = trim($part); |
| 63 | - if ($part !== '') { |
|
| 65 | + if ($part !== '') |
|
| 66 | + { |
|
| 64 | 67 | $header->addItem($part); |
| 65 | 68 | } |
| 66 | 69 | } |
@@ -103,11 +106,13 @@ discard block |
||
| 103 | 106 | */ |
| 104 | 107 | public function getAll(): array |
| 105 | 108 | { |
| 106 | - if (!$this->sorted) { |
|
| 109 | + if (!$this->sorted) |
|
| 110 | + { |
|
| 107 | 111 | /** |
| 108 | 112 | * Sort item in descending order. |
| 109 | 113 | */ |
| 110 | - uasort($this->items, static function (AcceptHeaderItem $a, AcceptHeaderItem $b) { |
|
| 114 | + uasort($this->items, static function (AcceptHeaderItem $a, AcceptHeaderItem $b) |
|
| 115 | + { |
|
| 111 | 116 | return self::compare($a, $b) * -1; |
| 112 | 117 | }); |
| 113 | 118 | |
@@ -124,11 +129,13 @@ discard block |
||
| 124 | 129 | */ |
| 125 | 130 | private function addItem($item): void |
| 126 | 131 | { |
| 127 | - if (is_scalar($item)) { |
|
| 132 | + if (is_scalar($item)) |
|
| 133 | + { |
|
| 128 | 134 | $item = AcceptHeaderItem::fromString((string)$item); |
| 129 | 135 | } |
| 130 | 136 | |
| 131 | - if (!$item instanceof AcceptHeaderItem) { |
|
| 137 | + if (!$item instanceof AcceptHeaderItem) |
|
| 138 | + { |
|
| 132 | 139 | throw new AcceptHeaderException(sprintf( |
| 133 | 140 | 'Accept Header item expected to be an instance of `%s` or a string, got `%s`', |
| 134 | 141 | AcceptHeaderItem::class, |
@@ -137,7 +144,8 @@ discard block |
||
| 137 | 144 | } |
| 138 | 145 | |
| 139 | 146 | $value = strtolower($item->getValue()); |
| 140 | - if ($value !== '' && (!$this->has($value) || self::compare($item, $this->get($value)) === 1)) { |
|
| 147 | + if ($value !== '' && (!$this->has($value) || self::compare($item, $this->get($value)) === 1)) |
|
| 148 | + { |
|
| 141 | 149 | $this->sorted = false; |
| 142 | 150 | $this->items[$value] = $item; |
| 143 | 151 | } |
@@ -153,9 +161,11 @@ discard block |
||
| 153 | 161 | */ |
| 154 | 162 | private static function compare(AcceptHeaderItem $a, AcceptHeaderItem $b): int |
| 155 | 163 | { |
| 156 | - if ($a->getQuality() === $b->getQuality()) { |
|
| 164 | + if ($a->getQuality() === $b->getQuality()) |
|
| 165 | + { |
|
| 157 | 166 | // If quality are same value with more params has more weight. |
| 158 | - if (count($a->getParams()) === count($b->getParams())) { |
|
| 167 | + if (count($a->getParams()) === count($b->getParams())) |
|
| 168 | + { |
|
| 159 | 169 | // If quality and params then check for specific type or subtype. |
| 160 | 170 | // Means */* or * has less weight. |
| 161 | 171 | return static::compareValue($a->getValue(), $b->getValue()); |
@@ -178,11 +188,13 @@ discard block |
||
| 178 | 188 | private static function compareValue(string $a, string $b): int |
| 179 | 189 | { |
| 180 | 190 | // Check "Accept" headers values with it is type and subtype. |
| 181 | - if (strpos($a, '/') !== false && strpos($b, '/') !== false) { |
|
| 191 | + if (strpos($a, '/') !== false && strpos($b, '/') !== false) |
|
| 192 | + { |
|
| 182 | 193 | [$typeA, $subtypeA] = explode('/', $a, 2); |
| 183 | 194 | [$typeB, $subtypeB] = explode('/', $b, 2); |
| 184 | 195 | |
| 185 | - if ($typeA === $typeB) { |
|
| 196 | + if ($typeA === $typeB) |
|
| 197 | + { |
|
| 186 | 198 | return static::compareAtomic($subtypeA, $subtypeB); |
| 187 | 199 | } |
| 188 | 200 | |
@@ -199,23 +211,28 @@ discard block |
||
| 199 | 211 | */ |
| 200 | 212 | private static function compareAtomic(string $a, string $b): int |
| 201 | 213 | { |
| 202 | - if (mb_strpos($a, '*/') === 0) { |
|
| 214 | + if (mb_strpos($a, '*/') === 0) |
|
| 215 | + { |
|
| 203 | 216 | $a = '*'; |
| 204 | 217 | } |
| 205 | 218 | |
| 206 | - if (mb_strpos($b, '*/') === 0) { |
|
| 219 | + if (mb_strpos($b, '*/') === 0) |
|
| 220 | + { |
|
| 207 | 221 | $b = '*'; |
| 208 | 222 | } |
| 209 | 223 | |
| 210 | - if (strtolower($a) === strtolower($b)) { |
|
| 224 | + if (strtolower($a) === strtolower($b)) |
|
| 225 | + { |
|
| 211 | 226 | return 0; |
| 212 | 227 | } |
| 213 | 228 | |
| 214 | - if ($a === '*') { |
|
| 229 | + if ($a === '*') |
|
| 230 | + { |
|
| 215 | 231 | return -1; |
| 216 | 232 | } |
| 217 | 233 | |
| 218 | - if ($b === '*') { |
|
| 234 | + if ($b === '*') |
|
| 235 | + { |
|
| 219 | 236 | return 1; |
| 220 | 237 | } |
| 221 | 238 | |