Open Journal Systems  3.3.0
EasyHandle.php
1 <?php
2 namespace GuzzleHttp\Handler;
3 
8 
14 final class EasyHandle
15 {
17  public $handle;
18 
20  public $sink;
21 
23  public $headers = [];
24 
26  public $response;
27 
29  public $request;
30 
32  public $options = [];
33 
35  public $errno = 0;
36 
39 
45  public function createResponse()
46  {
47  if (empty($this->headers)) {
48  throw new \RuntimeException('No headers have been received');
49  }
50 
51  // HTTP-version SP status-code SP reason-phrase
52  $startLine = explode(' ', array_shift($this->headers), 3);
53  $headers = \GuzzleHttp\headers_from_lines($this->headers);
54  $normalizedKeys = \GuzzleHttp\normalize_header_keys($headers);
55 
56  if (!empty($this->options['decode_content'])
57  && isset($normalizedKeys['content-encoding'])
58  ) {
59  $headers['x-encoded-content-encoding']
60  = $headers[$normalizedKeys['content-encoding']];
61  unset($headers[$normalizedKeys['content-encoding']]);
62  if (isset($normalizedKeys['content-length'])) {
63  $headers['x-encoded-content-length']
64  = $headers[$normalizedKeys['content-length']];
65 
66  $bodyLength = (int) $this->sink->getSize();
67  if ($bodyLength) {
68  $headers[$normalizedKeys['content-length']] = $bodyLength;
69  } else {
70  unset($headers[$normalizedKeys['content-length']]);
71  }
72  }
73  }
74 
75  // Attach a response to the easy handle with the parsed headers.
76  $this->response = new Response(
77  $startLine[1],
78  $headers,
79  $this->sink,
80  substr($startLine[0], 5),
81  isset($startLine[2]) ? (string) $startLine[2] : null
82  );
83  }
84 
85  public function __get($name)
86  {
87  $msg = $name === 'handle'
88  ? 'The EasyHandle has been released'
89  : 'Invalid property: ' . $name;
90  throw new \BadMethodCallException($msg);
91  }
92 }
GuzzleHttp\Handler\EasyHandle\$sink
$sink
Definition: EasyHandle.php:26
GuzzleHttp\Psr7\Response
Definition: vendor/guzzlehttp/psr7/src/Response.php:10
GuzzleHttp\Handler\EasyHandle\$response
$response
Definition: EasyHandle.php:38
Psr\Http\Message\StreamInterface
Definition: vendor/psr/http-message/src/StreamInterface.php:12
Psr\Http\Message\RequestInterface
Definition: vendor/psr/http-message/src/RequestInterface.php:24
GuzzleHttp\Handler\EasyHandle\$handle
$handle
Definition: EasyHandle.php:20
GuzzleHttp\Handler
Definition: CurlFactory.php:2
GuzzleHttp\Handler\EasyHandle\$headers
$headers
Definition: EasyHandle.php:32
GuzzleHttp\Handler\EasyHandle\__get
__get($name)
Definition: EasyHandle.php:109
GuzzleHttp\Handler\EasyHandle\$request
$request
Definition: EasyHandle.php:44
Psr\Http\Message\ResponseInterface
Definition: vendor/psr/http-message/src/ResponseInterface.php:20
GuzzleHttp\Handler\EasyHandle\createResponse
createResponse()
Definition: EasyHandle.php:69
GuzzleHttp\Handler\EasyHandle
Definition: EasyHandle.php:14
GuzzleHttp\Handler\EasyHandle\$onHeadersException
$onHeadersException
Definition: EasyHandle.php:62
GuzzleHttp\Handler\EasyHandle\$errno
$errno
Definition: EasyHandle.php:56
GuzzleHttp\Handler\EasyHandle\$options
$options
Definition: EasyHandle.php:50