1 | <?php |
||
36 | class CurlAdapter extends AbstractAdapter { |
||
37 | |||
38 | /** |
||
39 | * @var CurlInterface |
||
40 | */ |
||
41 | protected $curl; |
||
42 | |||
43 | /** |
||
44 | * @var \ArrayObject |
||
45 | */ |
||
46 | protected $opts; |
||
47 | |||
48 | /** |
||
49 | * @param Client $client |
||
50 | * @param CurlInterface $curl |
||
51 | */ |
||
52 | 4 | public function __construct(Client $client, CurlInterface $curl = null) { |
|
53 | 4 | parent::__construct($client); |
|
54 | 4 | $this->curl = $curl ?: AbstractCurl::createOptimalVersion(); |
|
55 | 4 | $this->curl->init(); |
|
56 | 4 | } |
|
57 | |||
58 | /** |
||
59 | * @return Curl |
||
60 | */ |
||
61 | 2 | public function getCurl() { |
|
62 | 2 | return $this->curl; |
|
63 | } |
||
64 | |||
65 | /** |
||
66 | * @return \ArrayObject |
||
67 | */ |
||
68 | 1 | public function getOpts() { |
|
69 | 1 | if ($this->opts === null) { |
|
70 | 1 | $this->opts = new \ArrayObject(array( |
|
71 | 1 | CURLOPT_CONNECTTIMEOUT => 10, |
|
72 | 1 | CURLOPT_TIMEOUT => 60, |
|
73 | 1 | CURLOPT_RETURNTRANSFER => true, |
|
74 | 1 | CURLOPT_HEADER => true, |
|
75 | 1 | CURLOPT_CAINFO => $this->getCaBundlePath(), |
|
76 | 1 | )); |
|
77 | 1 | } |
|
78 | |||
79 | 1 | return $this->opts; |
|
80 | } |
||
81 | |||
82 | /** |
||
83 | * @param \ArrayObject $opts |
||
84 | */ |
||
85 | 1 | public function setOpts(\ArrayObject $opts) { |
|
88 | |||
89 | /** |
||
90 | * @return int |
||
91 | */ |
||
92 | protected function getheaderSize() { |
||
93 | return $this->getCurl()->getInfo(CURLINFO_HEADER_SIZE); |
||
94 | } |
||
95 | |||
96 | /** |
||
97 | * Extracts the headers and the body into a two-part array |
||
98 | * @param string $raw_response |
||
99 | * @return array |
||
100 | */ |
||
101 | protected function extractResponseHeadersAndBody($raw_response) { |
||
102 | $header_size = $this->getheaderSize(); |
||
103 | |||
104 | $raw_headers = mb_substr($raw_response, 0, $header_size); |
||
105 | $raw_body = mb_substr($raw_response, $header_size); |
||
106 | |||
107 | return array(trim($raw_headers), trim($raw_body)); |
||
108 | } |
||
109 | |||
110 | /** |
||
111 | * @param Headers $headers |
||
112 | * @param string $raw_headers |
||
113 | */ |
||
114 | protected function parseHeaders(Headers $headers, $raw_headers) { |
||
133 | |||
134 | /** |
||
135 | * @param RequestInterface $request |
||
136 | * @return ResponseInterface |
||
137 | * @throws Exception |
||
138 | */ |
||
139 | public function sendRequest(RequestInterface $request) { |
||
201 | } |
||
202 |