|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* The Imaging Source Download System PHP Wrapper |
|
6
|
|
|
* |
|
7
|
|
|
* PHP wrapper for The Imaging Source Download System Web API. Authored and supported by The Imaging Source Europe GmbH. |
|
8
|
|
|
* |
|
9
|
|
|
* @link http://dl-gui.theimagingsource.com to learn more about The Imaging Source Download System |
|
10
|
|
|
* @link https://github.com/jonathanmaron/theimagingsource-tisd-sdk for the canonical source repository |
|
11
|
|
|
* @license https://github.com/jonathanmaron/theimagingsource-tisd-sdk/blob/master/LICENSE.md |
|
12
|
|
|
* @copyright © 2022 The Imaging Source Europe GmbH |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace Tisd\Sdk; |
|
16
|
|
|
|
|
17
|
|
|
use Tisd\Sdk\Cache\Cache; |
|
18
|
|
|
use Tisd\Sdk\Defaults\Defaults; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Class Sdk |
|
22
|
|
|
* |
|
23
|
|
|
* @package Tisd\Sdk |
|
24
|
|
|
*/ |
|
25
|
|
|
class Sdk |
|
26
|
|
|
{ |
|
27
|
|
|
use ConsolidatedTrait; |
|
28
|
|
|
use ContextsTrait; |
|
29
|
|
|
use FilterTrait; |
|
30
|
|
|
use LocalesTrait; |
|
31
|
|
|
use MetaTrait; |
|
32
|
|
|
use PackagesTrait; |
|
33
|
|
|
use PackageTrait; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Cache |
|
37
|
|
|
* |
|
38
|
|
|
* @var Cache |
|
39
|
|
|
*/ |
|
40
|
|
|
protected Cache $cache; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Context |
|
44
|
|
|
* |
|
45
|
|
|
* @var string |
|
46
|
|
|
*/ |
|
47
|
|
|
protected string $context; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Hostname |
|
51
|
|
|
* |
|
52
|
|
|
* @var string |
|
53
|
|
|
*/ |
|
54
|
|
|
protected string $hostname; |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Locale |
|
58
|
|
|
* |
|
59
|
|
|
* @var string |
|
60
|
|
|
*/ |
|
61
|
|
|
protected string $locale; |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Timeout |
|
65
|
|
|
* |
|
66
|
|
|
* @var int |
|
67
|
|
|
*/ |
|
68
|
|
|
protected int $timeout; |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Version |
|
72
|
|
|
* |
|
73
|
|
|
* @var string |
|
74
|
|
|
*/ |
|
75
|
|
|
protected string $version; |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Sdk constructor |
|
79
|
|
|
* |
|
80
|
|
|
* @param array $options |
|
81
|
|
|
*/ |
|
82
|
46 |
|
public function __construct(array $options = []) |
|
83
|
|
|
{ |
|
84
|
46 |
|
$defaults = new Defaults(); |
|
85
|
|
|
|
|
86
|
46 |
|
$optionKeys = [ |
|
87
|
|
|
'context', |
|
88
|
|
|
'hostname', |
|
89
|
|
|
'locale', |
|
90
|
|
|
'timeout', |
|
91
|
|
|
'version', |
|
92
|
|
|
]; |
|
93
|
|
|
|
|
94
|
46 |
|
foreach ($optionKeys as $optionKey) { |
|
95
|
46 |
|
if (array_key_exists($optionKey, $options)) { |
|
96
|
1 |
|
$value = $options[$optionKey]; |
|
97
|
|
|
} else { |
|
98
|
46 |
|
$getter = sprintf('get%s', ucfirst($optionKey)); |
|
99
|
|
|
// @phpstan-ignore-next-line |
|
100
|
46 |
|
$value = $defaults->$getter(); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
46 |
|
$setter = sprintf('set%s', ucfirst($optionKey)); |
|
104
|
|
|
// @phpstan-ignore-next-line |
|
105
|
46 |
|
$this->$setter($value); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
46 |
|
$cache = new Cache(); |
|
109
|
|
|
|
|
110
|
46 |
|
if (array_key_exists('ttl', $options)) { |
|
111
|
1 |
|
$ttl = $options['ttl']; |
|
112
|
|
|
} else { |
|
113
|
46 |
|
$ttl = Defaults::TTL; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
46 |
|
$cache->setTtl($ttl); |
|
117
|
|
|
|
|
118
|
46 |
|
$this->setCache($cache); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* Get the Cache instance |
|
123
|
|
|
* |
|
124
|
|
|
* @return Cache |
|
125
|
|
|
*/ |
|
126
|
40 |
|
public function getCache(): Cache |
|
127
|
|
|
{ |
|
128
|
40 |
|
return $this->cache; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* Set the Cache instance |
|
133
|
|
|
* |
|
134
|
|
|
* @param Cache $cache |
|
135
|
|
|
* |
|
136
|
|
|
* @return $this |
|
137
|
|
|
*/ |
|
138
|
46 |
|
public function setCache(Cache $cache): self |
|
139
|
|
|
{ |
|
140
|
46 |
|
$this->cache = $cache; |
|
141
|
|
|
|
|
142
|
46 |
|
return $this; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* Get the context |
|
147
|
|
|
* |
|
148
|
|
|
* @return string |
|
149
|
|
|
*/ |
|
150
|
40 |
|
public function getContext(): string |
|
151
|
|
|
{ |
|
152
|
40 |
|
return $this->context; |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* Set the context |
|
157
|
|
|
* |
|
158
|
|
|
* @param string $context |
|
159
|
|
|
* |
|
160
|
|
|
* @return $this |
|
161
|
|
|
*/ |
|
162
|
46 |
|
public function setContext(string $context): self |
|
163
|
|
|
{ |
|
164
|
46 |
|
$this->context = $context; |
|
165
|
|
|
|
|
166
|
46 |
|
return $this; |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* Get the hostname |
|
171
|
|
|
* |
|
172
|
|
|
* @return string |
|
173
|
|
|
*/ |
|
174
|
7 |
|
public function getHostname(): string |
|
175
|
|
|
{ |
|
176
|
7 |
|
return $this->hostname; |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
/** |
|
180
|
|
|
* Set the hostname |
|
181
|
|
|
* |
|
182
|
|
|
* @param string $hostname |
|
183
|
|
|
* |
|
184
|
|
|
* @return $this |
|
185
|
|
|
*/ |
|
186
|
46 |
|
public function setHostname(string $hostname): self |
|
187
|
|
|
{ |
|
188
|
46 |
|
$this->hostname = $hostname; |
|
189
|
|
|
|
|
190
|
46 |
|
return $this; |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
/** |
|
194
|
|
|
* Get the locale |
|
195
|
|
|
* |
|
196
|
|
|
* @return string |
|
197
|
|
|
*/ |
|
198
|
40 |
|
public function getLocale(): string |
|
199
|
|
|
{ |
|
200
|
40 |
|
return $this->locale; |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
/** |
|
204
|
|
|
* Set the locale |
|
205
|
|
|
* |
|
206
|
|
|
* @param string $locale |
|
207
|
|
|
* |
|
208
|
|
|
* @return $this |
|
209
|
|
|
*/ |
|
210
|
46 |
|
public function setLocale(string $locale): self |
|
211
|
|
|
{ |
|
212
|
46 |
|
$this->locale = $locale; |
|
213
|
|
|
|
|
214
|
46 |
|
$this->setConsolidated([]); |
|
215
|
|
|
|
|
216
|
46 |
|
return $this; |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
/** |
|
220
|
|
|
* Get the timeout |
|
221
|
|
|
* |
|
222
|
|
|
* @return int |
|
223
|
|
|
*/ |
|
224
|
7 |
|
public function getTimeout(): int |
|
225
|
|
|
{ |
|
226
|
7 |
|
return $this->timeout; |
|
227
|
|
|
} |
|
228
|
|
|
|
|
229
|
|
|
/** |
|
230
|
|
|
* Set the timeout |
|
231
|
|
|
* |
|
232
|
|
|
* @param int $timeout |
|
233
|
|
|
* |
|
234
|
|
|
* @return $this |
|
235
|
|
|
*/ |
|
236
|
46 |
|
public function setTimeout(int $timeout): self |
|
237
|
|
|
{ |
|
238
|
46 |
|
$this->timeout = $timeout; |
|
239
|
|
|
|
|
240
|
46 |
|
return $this; |
|
241
|
|
|
} |
|
242
|
|
|
|
|
243
|
|
|
/** |
|
244
|
|
|
* Get the version |
|
245
|
|
|
* |
|
246
|
|
|
* @return string |
|
247
|
|
|
*/ |
|
248
|
7 |
|
public function getVersion(): string |
|
249
|
|
|
{ |
|
250
|
7 |
|
return $this->version; |
|
251
|
|
|
} |
|
252
|
|
|
|
|
253
|
|
|
/** |
|
254
|
|
|
* Set the version |
|
255
|
|
|
* |
|
256
|
|
|
* @param string $version |
|
257
|
|
|
* |
|
258
|
|
|
* @return $this |
|
259
|
|
|
*/ |
|
260
|
46 |
|
public function setVersion(string $version): self |
|
261
|
|
|
{ |
|
262
|
46 |
|
$this->version = $version; |
|
263
|
|
|
|
|
264
|
46 |
|
return $this; |
|
265
|
|
|
} |
|
266
|
|
|
} |
|
267
|
|
|
|