forked from amzn/amazon-advertising-api-php-sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCurlRequest.php
67 lines (57 loc) · 1.66 KB
/
CurlRequest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
namespace AmazonAdvertisingApi;
class CurlRequest
{
private $handle = null;
public $requestId = null;
public function __construct($host = null)
{
$this->reset($host);
}
public function reset($host = null)
{
$this->handle = curl_init();
curl_setopt($this->handle, CURLOPT_PORT, 443);
curl_setopt($this->handle, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($this->handle, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($this->handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->handle, CURLOPT_HEADER, false);
if (defined("CURLOPT_IPRESOLVE")) {
curl_setopt($this->handle, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
}
curl_setopt($this->handle, CURLOPT_HEADERFUNCTION, array($this, "_handleHeaderLine"));
}
public function setOption($name, $value)
{
curl_setopt($this->handle, $name, $value);
}
public function execute()
{
return curl_exec($this->handle);
}
public function getInfo()
{
return curl_getinfo($this->handle);
}
public function getError()
{
return curl_error($this->handle);
}
public function close()
{
curl_close($this->handle);
}
private function _handleHeaderLine($ch, $line)
{
$matches = array();
if (preg_match("/x-amz-request-id:\ \S+/", $line)) {
preg_match_all("/[^\ ]\S+/", $line, $matches);
if (count($matches) > 0) {
if (count($matches[0]) > 1) {
$this->requestId = $matches[0][1];
}
}
}
return strlen($line);
}
}