1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* ActiveRecord for API |
4
|
|
|
* |
5
|
|
|
* @link https://github.com/hiqdev/yii2-hiart |
6
|
|
|
* @package yii2-hiart |
7
|
|
|
* @license BSD-3-Clause |
8
|
|
|
* @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/) |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace hiqdev\hiart\curl; |
12
|
|
|
|
13
|
|
|
use hiqdev\hiart\AbstractRequest; |
14
|
|
|
use hiqdev\hiart\AbstractResponse; |
15
|
|
|
use hiqdev\hiart\ResponseErrorException; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* For creating response manually. |
19
|
|
|
*/ |
20
|
|
|
class ManualResponse extends AbstractResponse |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var mixed |
24
|
|
|
*/ |
25
|
|
|
protected $data; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var array[] |
29
|
|
|
*/ |
30
|
|
|
protected $headers = []; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
protected $statusCode; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var string |
39
|
|
|
*/ |
40
|
|
|
protected $reasonPhrase; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param AbstractRequest $request |
44
|
|
|
* @param mixed $data |
45
|
|
|
* @param array $headers |
46
|
|
|
* @param string $statusCode |
47
|
|
|
* @param string $reasonPhrase |
48
|
|
|
*/ |
49
|
|
|
public function __construct(RequestInterface $request, $data, array $headers = [], $statusCode = null, $reasonPhrase = null) |
50
|
|
|
{ |
51
|
|
|
$this->request = $request; |
|
|
|
|
52
|
|
|
$this->data = $data; |
53
|
|
|
$this->headers = $headers; |
54
|
|
|
$this->statusCode = $statusCode; |
55
|
|
|
$this->reasonPhrase = $reasonPhrase; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return mixed |
60
|
|
|
*/ |
61
|
|
|
public function getData() |
62
|
|
|
{ |
63
|
|
|
return $this->data; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return mixed |
68
|
|
|
*/ |
69
|
|
|
public function getRawData() |
70
|
|
|
{ |
71
|
|
|
return $this->data; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @param string $name the header name |
76
|
|
|
* @return array|null |
77
|
|
|
*/ |
78
|
|
|
public function getHeader($name) |
79
|
|
|
{ |
80
|
|
|
return isset($this->headers[strtolower($name)]) ? $this->headers[strtolower($name)] : null; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* {@inheritdoc} |
85
|
|
|
*/ |
86
|
|
|
public function getStatusCode() |
87
|
|
|
{ |
88
|
|
|
return $this->statusCode; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* {@inheritdoc} |
93
|
|
|
*/ |
94
|
|
|
public function getReasonPhrase() |
95
|
|
|
{ |
96
|
|
|
return $this->reasonPhrase; |
|
|
|
|
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Returns array of all headers. |
101
|
|
|
* Key - Header name |
102
|
|
|
* Value - array of header values. For example:. |
103
|
|
|
* |
104
|
|
|
* ```php |
105
|
|
|
* ['Location' => ['http://example.com'], 'Expires' => ['Thu, 01 Jan 1970 00:00:00 GMT']] |
106
|
|
|
* @return array |
107
|
|
|
*/ |
108
|
|
|
public function getHeaders() |
109
|
|
|
{ |
110
|
|
|
return $this->headers; |
|
|
|
|
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|
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..