1 | <?php |
||
23 | abstract class AbstractStreamHttpAdapter extends AbstractHttpAdapter |
||
24 | { |
||
25 | /** |
||
26 | * {@inheritdoc} |
||
27 | */ |
||
28 | protected function sendInternalRequest(InternalRequestInterface $internalRequest) |
||
29 | { |
||
30 | $context = stream_context_create([ |
||
31 | 'http' => [ |
||
32 | 'follow_location' => false, |
||
33 | 'max_redirects' => 1, |
||
34 | 'ignore_errors' => true, |
||
35 | 'timeout' => $this->getConfiguration()->getTimeout(), |
||
36 | 'protocol_version' => $internalRequest->getProtocolVersion(), |
||
37 | 'method' => $internalRequest->getMethod(), |
||
38 | 'header' => $this->prepareHeaders($internalRequest, false), |
||
39 | 'content' => $this->prepareBody($internalRequest), |
||
40 | ], |
||
41 | ]); |
||
42 | |||
43 | list($body, $headers) = $this->process($uri = (string) $internalRequest->getUri(), $context); |
||
44 | |||
45 | if ($body === false) { |
||
46 | $error = error_get_last(); |
||
47 | throw HttpAdapterException::cannotFetchUri($uri, $this->getName(), $error['message']); |
||
48 | } |
||
49 | |||
50 | return $this->getConfiguration()->getMessageFactory()->createResponse( |
||
51 | StatusCodeExtractor::extract($headers), |
||
52 | ProtocolVersionExtractor::extract($headers), |
||
53 | HeadersNormalizer::normalize($headers), |
||
54 | BodyNormalizer::normalize($body, $internalRequest->getMethod()) |
||
55 | ); |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * @param string $uri |
||
60 | * @param resource $context |
||
61 | * |
||
62 | * @return array |
||
63 | */ |
||
64 | abstract protected function process($uri, $context); |
||
65 | } |
||
66 |