1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author @jenschude <[email protected]> |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace Commercetools\Core\Client; |
7
|
|
|
|
8
|
|
|
use Commercetools\Core\ConfigObject; |
9
|
|
|
use Commercetools\Core\Helper\CorrelationIdProvider; |
10
|
|
|
use Commercetools\Core\Helper\DefaultCorrelationIdProvider; |
11
|
|
|
use Psr\Log\LogLevel; |
12
|
|
|
|
13
|
|
|
class ClientConfig extends ConfigObject |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
protected $project; |
19
|
|
|
|
20
|
|
|
protected $baseUri; |
21
|
|
|
|
22
|
|
|
protected $adapter; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var bool |
26
|
|
|
*/ |
27
|
|
|
protected $throwExceptions = false; |
28
|
|
|
|
29
|
|
|
protected $acceptEncoding = 'gzip'; |
30
|
|
|
|
31
|
|
|
protected $clientOptions = [ |
32
|
|
|
'concurrency' => 25 |
33
|
|
|
]; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var string |
37
|
|
|
*/ |
38
|
|
|
protected $logLevel = LogLevel::INFO; |
39
|
|
|
|
40
|
|
|
protected $messageFormatter; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var bool |
44
|
|
|
*/ |
45
|
|
|
protected $enableCorrelationId = false; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var CorrelationIdProvider |
49
|
|
|
*/ |
50
|
|
|
protected $correlationIdProvider; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* ClientOptions constructor. |
54
|
|
|
* @param $baseUri |
55
|
|
|
*/ |
56
|
109 |
|
public function __construct($baseUri) |
57
|
|
|
{ |
58
|
109 |
|
$this->baseUri = $baseUri; |
59
|
109 |
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @return mixed |
63
|
|
|
*/ |
64
|
83 |
|
public function getBaseUri() |
65
|
|
|
{ |
66
|
83 |
|
return $this->baseUri; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param mixed $baseUri |
71
|
|
|
* @return ClientConfig |
72
|
|
|
*/ |
73
|
90 |
|
public function setBaseUri($baseUri) |
74
|
|
|
{ |
75
|
90 |
|
$this->baseUri = $baseUri; |
76
|
90 |
|
return $this; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @return mixed |
81
|
|
|
*/ |
82
|
78 |
|
public function getAdapter() |
83
|
|
|
{ |
84
|
78 |
|
return $this->adapter; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @param mixed $adapter |
89
|
|
|
* @return ClientConfig |
90
|
|
|
*/ |
91
|
|
|
public function setAdapter($adapter) |
92
|
|
|
{ |
93
|
|
|
$this->adapter = $adapter; |
94
|
|
|
return $this; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @return bool |
99
|
|
|
*/ |
100
|
90 |
|
public function isThrowExceptions() |
101
|
|
|
{ |
102
|
90 |
|
return $this->throwExceptions; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @param bool $throwExceptions |
107
|
|
|
* @return ClientConfig |
108
|
|
|
*/ |
109
|
9 |
|
public function setThrowExceptions($throwExceptions) |
110
|
|
|
{ |
111
|
9 |
|
$this->throwExceptions = (bool)$throwExceptions; |
112
|
9 |
|
return $this; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @return string |
117
|
|
|
*/ |
118
|
77 |
|
public function getAcceptEncoding() |
119
|
|
|
{ |
120
|
77 |
|
return $this->acceptEncoding; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @param string $acceptEncoding |
125
|
|
|
* @return ClientConfig |
126
|
|
|
*/ |
127
|
|
|
public function setAcceptEncoding($acceptEncoding) |
128
|
|
|
{ |
129
|
|
|
$this->acceptEncoding = $acceptEncoding; |
130
|
|
|
return $this; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @return array |
135
|
|
|
*/ |
136
|
76 |
|
public function getClientOptions() |
137
|
|
|
{ |
138
|
76 |
|
return $this->clientOptions; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @param array $clientOptions |
143
|
|
|
* @return ClientConfig |
144
|
|
|
*/ |
145
|
4 |
|
public function setClientOptions($clientOptions) |
146
|
|
|
{ |
147
|
4 |
|
$this->clientOptions = $clientOptions; |
148
|
4 |
|
return $this; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @return string |
153
|
|
|
*/ |
154
|
41 |
|
public function getLogLevel() |
155
|
|
|
{ |
156
|
41 |
|
return $this->logLevel; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @param string $logLevel |
161
|
|
|
* @return ClientConfig |
162
|
|
|
*/ |
163
|
1 |
|
public function setLogLevel($logLevel) |
164
|
|
|
{ |
165
|
1 |
|
$this->logLevel = $logLevel; |
166
|
1 |
|
return $this; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* @deprecated use getClientOptions()['concurrency'] instead |
171
|
|
|
* @return int |
172
|
|
|
*/ |
173
|
1 |
|
public function getBatchPoolSize() |
174
|
|
|
{ |
175
|
1 |
|
return $this->clientOptions['concurrency']; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* @deprecated use setClientOptions(['concurrency' => 5]) instead |
180
|
|
|
* @param int $batchPoolSize |
181
|
|
|
* @return $this |
182
|
|
|
*/ |
183
|
1 |
|
public function setBatchPoolSize($batchPoolSize) |
184
|
|
|
{ |
185
|
1 |
|
$this->clientOptions['concurrency'] = $batchPoolSize; |
186
|
|
|
|
187
|
1 |
|
return $this; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* @return mixed |
192
|
|
|
*/ |
193
|
41 |
|
public function getMessageFormatter() |
194
|
|
|
{ |
195
|
41 |
|
return $this->messageFormatter; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* @param mixed $messageFormatter |
200
|
|
|
* @return $this |
201
|
|
|
*/ |
202
|
|
|
public function setMessageFormatter($messageFormatter) |
203
|
|
|
{ |
204
|
|
|
$this->messageFormatter = $messageFormatter; |
205
|
|
|
return $this; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* @return bool |
210
|
|
|
*/ |
211
|
76 |
|
public function isEnableCorrelationId() |
212
|
|
|
{ |
213
|
76 |
|
return $this->enableCorrelationId; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* @param bool $enableCorrelationId |
218
|
|
|
* @return $this |
219
|
|
|
*/ |
220
|
41 |
|
public function setEnableCorrelationId($enableCorrelationId) |
221
|
|
|
{ |
222
|
41 |
|
$this->enableCorrelationId = (bool)$enableCorrelationId; |
223
|
41 |
|
return $this; |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* @return CorrelationIdProvider|null |
228
|
|
|
*/ |
229
|
76 |
|
public function getCorrelationIdProvider() |
230
|
|
|
{ |
231
|
76 |
|
if (!$this->isEnableCorrelationId()) { |
232
|
75 |
|
return null; |
233
|
|
|
} |
234
|
34 |
|
if (is_null($this->correlationIdProvider)) { |
235
|
32 |
|
$this->correlationIdProvider = DefaultCorrelationIdProvider::of($this->getProject()); |
236
|
|
|
} |
237
|
34 |
|
return $this->correlationIdProvider; |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* @param CorrelationIdProvider $correlationIdProvider |
242
|
|
|
* @return $this |
243
|
|
|
*/ |
244
|
2 |
|
public function setCorrelationIdProvider(CorrelationIdProvider $correlationIdProvider) |
245
|
|
|
{ |
246
|
2 |
|
$this->correlationIdProvider = $correlationIdProvider; |
247
|
2 |
|
$this->setEnableCorrelationId(true); |
248
|
2 |
|
return $this; |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
/** |
252
|
|
|
* @return string |
253
|
|
|
*/ |
254
|
32 |
|
public function getProject() |
255
|
|
|
{ |
256
|
32 |
|
return $this->project; |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
/** |
260
|
|
|
* @param string $project |
261
|
|
|
* @return $this |
262
|
|
|
*/ |
263
|
102 |
|
public function setProject($project) |
264
|
|
|
{ |
265
|
102 |
|
$this->project = $project; |
266
|
|
|
|
267
|
102 |
|
return $this; |
268
|
|
|
} |
269
|
|
|
} |
270
|
|
|
|