|
5 | 5 | use Ivory\HttpAdapter\AbstractHttpAdapter; |
6 | 6 | use Ivory\HttpAdapter\HttpAdapterInterface; |
7 | 7 | use Ivory\HttpAdapter\Message\InternalRequestInterface; |
8 | | -use Ivory\HttpAdapter\Message\Stream\StringStream; |
9 | 8 | use Ivory\HttpAdapter\Message\RequestInterface; |
10 | 9 |
|
11 | 10 | class CachedResponseAdapter extends AbstractHttpAdapter |
@@ -39,28 +38,27 @@ public function getName() |
39 | 38 | /** |
40 | 39 | * {@inheritDoc} |
41 | 40 | */ |
42 | | - protected function doSend(InternalRequestInterface $internalRequest) |
| 41 | + protected function sendInternalRequest(InternalRequestInterface $internalRequest) |
43 | 42 | { |
44 | | - $url = $internalRequest->getUrl(); |
| 43 | + $url = (string) $internalRequest->getUri(); |
45 | 44 | if ($this->apiKey) { |
46 | 45 | $url = str_replace($this->apiKey, '[apikey]', $url); |
47 | 46 | } |
| 47 | + |
48 | 48 | $file = sprintf('%s/%s/%s', realpath(__DIR__ . '/../../'), $this->cacheDir, sha1($url)); |
49 | 49 |
|
50 | 50 | if ($this->useCache && is_file($file) && is_readable($file)) { |
51 | 51 | $content = unserialize(file_get_contents($file)); |
52 | | - $body = new StringStream($content); |
53 | | - |
54 | | - $response = $this->adapter->getConfiguration()->getMessageFactory()->createResponse( |
55 | | - 200, 'OK', RequestInterface::PROTOCOL_VERSION_1_1, [], $body |
56 | | - ); |
57 | 52 |
|
58 | 53 | if (!empty($content)) { |
59 | | - return $response; |
| 54 | + return $this->adapter |
| 55 | + ->getConfiguration() |
| 56 | + ->getMessageFactory() |
| 57 | + ->createResponse(200, RequestInterface::PROTOCOL_VERSION_1_1, [], $content); |
60 | 58 | } |
61 | 59 | } |
62 | 60 |
|
63 | | - $response = $this->adapter->get($internalRequest->getUrl()); |
| 61 | + $response = $this->adapter->get($url); |
64 | 62 |
|
65 | 63 | if ($this->useCache) { |
66 | 64 | file_put_contents($file, serialize((string) $response->getBody())); |
|
0 commit comments