1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* ©[2016] SugarCRM Inc. Licensed by SugarCRM under the Apache 2.0 license. |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace SugarAPI\SDK\Response\Abstracts; |
7
|
|
|
|
8
|
|
|
use SugarAPI\SDK\Response\Interfaces\ResponseInterface; |
9
|
|
|
|
10
|
|
|
abstract class AbstractResponse implements ResponseInterface { |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* The Curl Request Resource that was used when curl_exec was called |
14
|
|
|
* @var cURL resource handle |
15
|
|
|
*/ |
16
|
|
|
protected $CurlRequest; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Extracted headers from Curl Response |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
protected $headers; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Extracted body from Curl Response |
26
|
|
|
* @var mixed |
27
|
|
|
*/ |
28
|
|
|
protected $body; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* The HTTP Status Code of Request |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
protected $status; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* The last Curl Error that occurred |
38
|
|
|
* @var string|boolean - False when no Curl Error = 0 |
39
|
|
|
*/ |
40
|
|
|
protected $error; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* The cURL Resource information returned via curl_getinfo |
44
|
|
|
* @var array |
45
|
|
|
*/ |
46
|
|
|
protected $info; |
47
|
|
|
|
48
|
|
|
public function __construct($curlRequest,$curlResponse = NULL){ |
49
|
|
|
$this->CurlRequest = $curlRequest; |
50
|
|
|
if ($curlResponse!==NULL){ |
51
|
|
|
$this->setCurlResponse($curlResponse); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function setCurlResponse($curlResponse) { |
56
|
|
|
$this->extractInfo(); |
57
|
|
|
if (!$this->getError()){ |
58
|
|
|
$this->extractResponse($curlResponse); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Extract the information from the Curl Request via curl_getinfo |
64
|
|
|
* Setup the Status property to be equal to the http_code |
65
|
|
|
*/ |
66
|
|
|
protected function extractInfo(){ |
67
|
|
|
$this->info = curl_getinfo($this->CurlRequest); |
|
|
|
|
68
|
|
|
$this->status = $this->info['http_code']; |
69
|
|
|
if (curl_errno($this->CurlRequest)!== CURLE_OK){ |
70
|
|
|
$this->error = curl_error($this->CurlRequest); |
71
|
|
|
} |
72
|
|
|
$this->error = FALSE; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Seperate the Headers and Body from the CurlResponse, and set the object properties |
77
|
|
|
* @param string $curlResponse |
78
|
|
|
*/ |
79
|
|
|
protected function extractResponse($curlResponse){ |
80
|
|
|
$this->headers = substr($curlResponse, 0, $this->info['header_size']); |
81
|
|
|
$this->body = substr($curlResponse, $this->info['header_size']); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @inheritdoc |
86
|
|
|
*/ |
87
|
|
|
public function getStatus(){ |
88
|
|
|
return $this->status; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @inheritdoc |
93
|
|
|
*/ |
94
|
|
|
public function getBody(){ |
95
|
|
|
return $this->body; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @inheritdoc |
100
|
|
|
*/ |
101
|
|
|
public function getHeaders(){ |
102
|
|
|
return $this->headers; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @inheritdoc |
107
|
|
|
*/ |
108
|
|
|
public function getError(){ |
109
|
|
|
return $this->error; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @inheritdoc |
114
|
|
|
*/ |
115
|
|
|
public function getInfo(){ |
116
|
|
|
return $this->info; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
} |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..