@@ -1,4 +1,4 @@ |
||
| 1 | -<?php declare(strict_types=1); |
|
| 1 | +<?php declare(strict_types = 1); |
|
| 2 | 2 | |
| 3 | 3 | namespace WyriHaximus\React\Http\Middleware; |
| 4 | 4 | |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare(strict_types=1); |
|
| 1 | +<?php declare(strict_types = 1); |
|
| 2 | 2 | |
| 3 | 3 | namespace WyriHaximus\React\Http\Middleware; |
| 4 | 4 | |
@@ -40,10 +40,10 @@ discard block |
||
| 40 | 40 | |
| 41 | 41 | $key = $this->cacheConfiguration->cacheKey($request); |
| 42 | 42 | |
| 43 | - return $this->cache->get($key)->then(function ($json) { |
|
| 43 | + return $this->cache->get($key)->then(function($json) { |
|
| 44 | 44 | return $this->cacheConfiguration->cacheDecode($json); |
| 45 | - }, function () use ($next, $request, $key) { |
|
| 46 | - return resolve($next($request))->then(function (ResponseInterface $response) use ($request, $key) { |
|
| 45 | + }, function() use ($next, $request, $key) { |
|
| 46 | + return resolve($next($request))->then(function(ResponseInterface $response) use ($request, $key) { |
|
| 47 | 47 | if ($response->getBody() instanceof HttpBodyStream) { |
| 48 | 48 | return $response; |
| 49 | 49 | } |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | return $response; |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - $body = (string)$response->getBody(); |
|
| 55 | + $body = (string) $response->getBody(); |
|
| 56 | 56 | $encodedResponse = $this->cacheConfiguration->cacheEncode($response->withBody(stream_for($body))); |
| 57 | 57 | $this->cache->set($key, $encodedResponse); |
| 58 | 58 | |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare(strict_types=1); |
|
| 1 | +<?php declare(strict_types = 1); |
|
| 2 | 2 | |
| 3 | 3 | namespace WyriHaximus\React\Http\Middleware; |
| 4 | 4 | |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | $key = $request->getUri()->getPath(); |
| 96 | 96 | $query = $request->getUri()->getQuery(); |
| 97 | 97 | if (\strlen($query) > 0 && $this->queryInKey($key)) { |
| 98 | - $key .= '?' . $query; |
|
| 98 | + $key .= '?'.$query; |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | return $key; |
@@ -113,18 +113,18 @@ discard block |
||
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | return msgpack_pack([ |
| 116 | - 'body' => (string)$response->getBody(), |
|
| 116 | + 'body' => (string) $response->getBody(), |
|
| 117 | 117 | 'headers' => $headers, |
| 118 | 118 | 'code' => $response->getStatusCode(), |
| 119 | - 'time' => (int)$this->clock->now()->format('U'), |
|
| 119 | + 'time' => (int) $this->clock->now()->format('U'), |
|
| 120 | 120 | ]); |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | public function cacheDecode(string $response): ResponseInterface |
| 124 | 124 | { |
| 125 | 125 | $response = msgpack_unpack($response); |
| 126 | - $response['headers'] = (array)$response['headers']; |
|
| 127 | - $response['headers']['Age'] = (int)$this->clock->now()->format('U') - (int)$response['time']; |
|
| 126 | + $response['headers'] = (array) $response['headers']; |
|
| 127 | + $response['headers']['Age'] = (int) $this->clock->now()->format('U') - (int) $response['time']; |
|
| 128 | 128 | |
| 129 | 129 | return new Response($response['code'], $response['headers'], stream_for($response['body'])); |
| 130 | 130 | } |