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