1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Dmitry Gladyshev <[email protected]> |
4
|
|
|
* @date 17/08/2016 13:44 |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace Yandex\Direct\Transport; |
8
|
|
|
|
9
|
|
|
use Yandex\Direct\ConfigurableTrait; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class TransportRequest |
13
|
|
|
* @package Yandex\Direct |
14
|
|
|
*/ |
15
|
|
|
class Response implements ResponseInterface |
16
|
|
|
{ |
17
|
|
|
use ConfigurableTrait; |
18
|
|
|
|
19
|
|
|
const UNITS_TYPE_DEBIT = 0; |
20
|
|
|
const UNITS_TYPE_REST = 1; |
21
|
|
|
const UNITS_TYPE_LIMIT = 2; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Response constructor. |
25
|
|
|
* |
26
|
|
|
* @param array $responseAttributes |
27
|
|
|
*/ |
28
|
2 |
|
public function __construct(array $responseAttributes) |
29
|
|
|
{ |
30
|
2 |
|
$this->setOptions($responseAttributes); |
31
|
2 |
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
protected $service; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var string |
40
|
|
|
*/ |
41
|
|
|
protected $method; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var array |
45
|
|
|
*/ |
46
|
|
|
protected $units = [ |
47
|
|
|
self::UNITS_TYPE_DEBIT => null, |
48
|
|
|
self::UNITS_TYPE_LIMIT => null, |
49
|
|
|
self::UNITS_TYPE_REST => null |
50
|
|
|
]; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var string |
54
|
|
|
*/ |
55
|
|
|
protected $requestId; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @var string |
59
|
|
|
*/ |
60
|
|
|
protected $body; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @var int |
64
|
|
|
*/ |
65
|
|
|
protected $code; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @var array |
69
|
|
|
*/ |
70
|
|
|
protected $headers = []; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return array |
74
|
|
|
*/ |
75
|
1 |
|
public function getUnits() |
76
|
|
|
{ |
77
|
1 |
|
return $this->units; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param string $rawUnits |
82
|
|
|
*/ |
83
|
2 |
|
public function setUnits($rawUnits) |
84
|
|
|
{ |
85
|
2 |
|
if (is_array($rawUnits)) { |
86
|
1 |
|
$this->units = $rawUnits; |
87
|
1 |
|
} else { |
88
|
1 |
|
$units = explode('/', $rawUnits); |
89
|
1 |
|
if (is_array($units) && count($units) > 0) { |
90
|
1 |
|
$this->units = $units; |
91
|
1 |
|
} |
92
|
|
|
} |
93
|
2 |
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @inheritdoc |
97
|
|
|
*/ |
98
|
1 |
|
public function getRequestId() |
99
|
|
|
{ |
100
|
1 |
|
return $this->requestId; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @inheritdoc |
105
|
|
|
*/ |
106
|
1 |
|
public function getUnitsDebit() |
107
|
|
|
{ |
108
|
1 |
|
return $this->getUnits()[self::UNITS_TYPE_DEBIT]; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @inheritdoc |
113
|
|
|
*/ |
114
|
1 |
|
public function getUnitsRest() |
115
|
|
|
{ |
116
|
1 |
|
return $this->getUnits()[self::UNITS_TYPE_REST]; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @inheritdoc |
121
|
|
|
*/ |
122
|
1 |
|
public function getUnitsLimit() |
123
|
|
|
{ |
124
|
1 |
|
return $this->getUnits()[self::UNITS_TYPE_LIMIT]; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @inheritdoc |
129
|
|
|
*/ |
130
|
2 |
|
public function getBody() |
131
|
|
|
{ |
132
|
2 |
|
return $this->body; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @inheritdoc |
137
|
|
|
*/ |
138
|
1 |
|
public function getHeaders() |
139
|
|
|
{ |
140
|
1 |
|
return $this->headers; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @inheritdoc |
145
|
|
|
*/ |
146
|
|
|
public function getService() |
147
|
|
|
{ |
148
|
|
|
return $this->service; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @inheritdoc |
153
|
|
|
*/ |
154
|
|
|
public function getMethod() |
155
|
|
|
{ |
156
|
|
|
return $this->method; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
public function getCode() |
160
|
|
|
{ |
161
|
|
|
return $this->code; |
162
|
|
|
} |
163
|
|
|
} |
164
|
|
|
|