1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* This file is part of Phpfastcache. |
5
|
|
|
* |
6
|
|
|
* @license MIT License (MIT) |
7
|
|
|
* |
8
|
|
|
* For full copyright and license information, please see the docs/CREDITS.txt and LICENCE files. |
9
|
|
|
* |
10
|
|
|
* @author Georges.L (Geolim4) <[email protected]> |
11
|
|
|
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
declare(strict_types=1); |
15
|
|
|
|
16
|
|
|
namespace Phpfastcache\Drivers\Arangodb; |
17
|
|
|
|
18
|
|
|
use Phpfastcache\Config\ConfigurationOption; |
19
|
|
|
use Phpfastcache\Exceptions\PhpfastcacheLogicException; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @see https://github.com/arangodb/arangodb-php/blob/devel/examples/init.php |
23
|
|
|
* @SuppressWarnings(PHPMD.TooManyFields) |
24
|
|
|
*/ |
25
|
|
|
class Config extends ConfigurationOption |
26
|
|
|
{ |
27
|
|
|
protected string $database; |
28
|
|
|
|
29
|
|
|
protected string $collection; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* HTTP ENDPOINT: ssl://127.0.0.1:8529 |
33
|
|
|
* SSL ENDPOINT: ssl://127.0.0.1:8529 |
34
|
|
|
* UNIX ENDPOINT: unix:///tmp/arangodb.sock |
35
|
|
|
* Failover ENDPOINTS: ['tcp://127.0.0.1:8529', 'tcp://127.0.0.1:8529'] |
36
|
|
|
*/ |
37
|
|
|
protected string|array $endpoint = 'tcp://127.0.0.1:8529'; |
38
|
|
|
|
39
|
|
|
protected string $connection = 'Keep-Alive'; // enum{'Close', 'Keep-Alive'} |
40
|
|
|
|
41
|
|
|
protected string $authType = 'Basic'; // enum{'Bearer', 'Basic'} |
42
|
|
|
|
43
|
|
|
protected string $authUser = ''; |
44
|
|
|
|
45
|
|
|
protected string $authPasswd = ''; |
46
|
|
|
|
47
|
|
|
protected ?string $authJwt = null; |
48
|
|
|
|
49
|
|
|
protected bool $autoCreate = false; // Do not create unknown collections automatically |
50
|
|
|
|
51
|
|
|
protected int $connectTimeout = 3; |
52
|
|
|
|
53
|
|
|
protected int $requestTimeout = 5; |
54
|
|
|
|
55
|
|
|
protected string $updatePolicy = 'last'; |
56
|
|
|
|
57
|
|
|
protected bool $verifyCert = true; |
58
|
|
|
|
59
|
|
|
protected bool $selfSigned = true; |
60
|
|
|
|
61
|
|
|
protected string $ciphers = 'DEFAULT'; // @see https://www.openssl.org/docs/manmaster/apps/ciphers.html |
62
|
|
|
|
63
|
|
|
protected ?\Closure $traceFunction = null; |
64
|
|
|
|
65
|
|
|
public function getDatabase(): string |
66
|
|
|
{ |
67
|
|
|
return $this->database; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @throws PhpfastcacheLogicException |
72
|
|
|
*/ |
73
|
|
|
public function setDatabase(string $database): Config |
74
|
|
|
{ |
75
|
|
|
$this->enforceLockedProperty(__FUNCTION__); |
76
|
|
|
$this->database = $database; |
77
|
|
|
return $this; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function getCollection(): string |
81
|
|
|
{ |
82
|
|
|
return $this->collection; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @throws PhpfastcacheLogicException |
87
|
|
|
*/ |
88
|
|
|
public function setCollection(string $collection): Config |
89
|
|
|
{ |
90
|
|
|
$this->enforceLockedProperty(__FUNCTION__); |
91
|
|
|
$this->collection = $collection; |
92
|
|
|
return $this; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function getEndpoint(): string|array |
96
|
|
|
{ |
97
|
|
|
return $this->endpoint; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @throws PhpfastcacheLogicException |
102
|
|
|
*/ |
103
|
|
|
public function setEndpoint(string|array $endpoint): Config |
104
|
|
|
{ |
105
|
|
|
$this->enforceLockedProperty(__FUNCTION__); |
106
|
|
|
$this->endpoint = $endpoint; |
107
|
|
|
return $this; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public function getConnection(): string |
111
|
|
|
{ |
112
|
|
|
return $this->connection; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @throws PhpfastcacheLogicException |
117
|
|
|
*/ |
118
|
|
|
public function setConnection(string $connection): Config |
119
|
|
|
{ |
120
|
|
|
$this->enforceLockedProperty(__FUNCTION__); |
121
|
|
|
$this->connection = $connection; |
122
|
|
|
return $this; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
public function getAuthType(): string |
126
|
|
|
{ |
127
|
|
|
return $this->authType; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @throws PhpfastcacheLogicException |
132
|
|
|
*/ |
133
|
|
|
public function setAuthType(string $authType): Config |
134
|
|
|
{ |
135
|
|
|
$this->enforceLockedProperty(__FUNCTION__); |
136
|
|
|
$this->authType = $authType; |
137
|
|
|
return $this; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
public function getAuthUser(): string |
141
|
|
|
{ |
142
|
|
|
return $this->authUser; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @throws PhpfastcacheLogicException |
147
|
|
|
*/ |
148
|
|
|
public function setAuthUser(string $authUser): Config |
149
|
|
|
{ |
150
|
|
|
$this->enforceLockedProperty(__FUNCTION__); |
151
|
|
|
$this->authUser = $authUser; |
152
|
|
|
return $this; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
public function getAuthPasswd(): string |
156
|
|
|
{ |
157
|
|
|
return $this->authPasswd; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @throws PhpfastcacheLogicException |
162
|
|
|
*/ |
163
|
|
|
public function setAuthPasswd(string $authPasswd): Config |
164
|
|
|
{ |
165
|
|
|
$this->enforceLockedProperty(__FUNCTION__); |
166
|
|
|
$this->authPasswd = $authPasswd; |
167
|
|
|
return $this; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* @return string|null |
172
|
|
|
*/ |
173
|
|
|
public function getAuthJwt(): ?string |
174
|
|
|
{ |
175
|
|
|
return $this->authJwt; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* @param string|null $authJwt |
180
|
|
|
* @return Config |
181
|
|
|
* @throws PhpfastcacheLogicException |
182
|
|
|
*/ |
183
|
|
|
public function setAuthJwt(?string $authJwt): Config |
184
|
|
|
{ |
185
|
|
|
$this->enforceLockedProperty(__FUNCTION__); |
186
|
|
|
$this->authJwt = $authJwt; |
187
|
|
|
return $this; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
public function isAutoCreate(): bool |
191
|
|
|
{ |
192
|
|
|
return $this->autoCreate; |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* @throws PhpfastcacheLogicException |
197
|
|
|
*/ |
198
|
|
|
public function setAutoCreate(bool $autoCreate): Config |
199
|
|
|
{ |
200
|
|
|
$this->enforceLockedProperty(__FUNCTION__); |
201
|
|
|
$this->autoCreate = $autoCreate; |
202
|
|
|
return $this; |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
public function getConnectTimeout(): int |
206
|
|
|
{ |
207
|
|
|
return $this->connectTimeout; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* @throws PhpfastcacheLogicException |
212
|
|
|
*/ |
213
|
|
|
public function setConnectTimeout(int $connectTimeout): Config |
214
|
|
|
{ |
215
|
|
|
$this->enforceLockedProperty(__FUNCTION__); |
216
|
|
|
$this->connectTimeout = $connectTimeout; |
217
|
|
|
return $this; |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
public function getRequestTimeout(): int |
221
|
|
|
{ |
222
|
|
|
return $this->requestTimeout; |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* @throws PhpfastcacheLogicException |
227
|
|
|
*/ |
228
|
|
|
public function setRequestTimeout(int $requestTimeout): Config |
229
|
|
|
{ |
230
|
|
|
$this->enforceLockedProperty(__FUNCTION__); |
231
|
|
|
$this->requestTimeout = $requestTimeout; |
232
|
|
|
return $this; |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
public function getUpdatePolicy(): string |
236
|
|
|
{ |
237
|
|
|
return $this->updatePolicy; |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* @throws PhpfastcacheLogicException |
242
|
|
|
*/ |
243
|
|
|
public function setUpdatePolicy(string $updatePolicy): Config |
244
|
|
|
{ |
245
|
|
|
$this->enforceLockedProperty(__FUNCTION__); |
246
|
|
|
$this->updatePolicy = $updatePolicy; |
247
|
|
|
return $this; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
public function isVerifyCert(): bool |
251
|
|
|
{ |
252
|
|
|
return $this->verifyCert; |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
/** |
256
|
|
|
* @throws PhpfastcacheLogicException |
257
|
|
|
*/ |
258
|
|
|
public function setVerifyCert(bool $verifyCert): Config |
259
|
|
|
{ |
260
|
|
|
$this->enforceLockedProperty(__FUNCTION__); |
261
|
|
|
$this->verifyCert = $verifyCert; |
262
|
|
|
return $this; |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
public function isSelfSigned(): bool |
266
|
|
|
{ |
267
|
|
|
return $this->selfSigned; |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
/** |
271
|
|
|
* @throws PhpfastcacheLogicException |
272
|
|
|
*/ |
273
|
|
|
public function setSelfSigned(bool $selfSigned): Config |
274
|
|
|
{ |
275
|
|
|
$this->enforceLockedProperty(__FUNCTION__); |
276
|
|
|
$this->selfSigned = $selfSigned; |
277
|
|
|
return $this; |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
public function getCiphers(): string |
281
|
|
|
{ |
282
|
|
|
return $this->ciphers; |
283
|
|
|
} |
284
|
|
|
|
285
|
|
|
/** |
286
|
|
|
* @throws PhpfastcacheLogicException |
287
|
|
|
*/ |
288
|
|
|
public function setCiphers(string $ciphers): Config |
289
|
|
|
{ |
290
|
|
|
$this->enforceLockedProperty(__FUNCTION__); |
291
|
|
|
$this->ciphers = $ciphers; |
292
|
|
|
return $this; |
293
|
|
|
} |
294
|
|
|
|
295
|
|
|
/** |
296
|
|
|
* @return \Closure|null |
297
|
|
|
*/ |
298
|
|
|
public function getTraceFunction(): ?\Closure |
299
|
|
|
{ |
300
|
|
|
return $this->traceFunction; |
301
|
|
|
} |
302
|
|
|
|
303
|
|
|
/** |
304
|
|
|
* @param \Closure|null $traceFunction |
305
|
|
|
* @return Config |
306
|
|
|
* @throws PhpfastcacheLogicException |
307
|
|
|
*/ |
308
|
|
|
public function setTraceFunction(?\Closure $traceFunction): Config |
309
|
|
|
{ |
310
|
|
|
$this->enforceLockedProperty(__FUNCTION__); |
311
|
|
|
$this->traceFunction = $traceFunction; |
312
|
|
|
return $this; |
313
|
|
|
} |
314
|
|
|
} |
315
|
|
|
|