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 file. |
9
|
|
|
* |
10
|
|
|
* @author Khoa Bui (khoaofgod) <[email protected]> https://www.phpfastcache.com |
11
|
|
|
* @author Georges.L (Geolim4) <[email protected]> |
12
|
|
|
* |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
declare(strict_types=1); |
16
|
|
|
|
17
|
|
|
namespace Phpfastcache\Drivers\Mongodb; |
18
|
|
|
|
19
|
|
|
use Phpfastcache\Config\ConfigurationOption; |
20
|
|
|
|
21
|
|
|
class Config extends ConfigurationOption |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
protected $host = '127.0.0.1'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var int |
30
|
|
|
*/ |
31
|
|
|
protected $port = 27017; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var int |
35
|
|
|
*/ |
36
|
|
|
protected $timeout = 3; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var string |
40
|
|
|
*/ |
41
|
|
|
protected $username = ''; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var string |
45
|
|
|
*/ |
46
|
|
|
protected $password = ''; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var array |
50
|
|
|
*/ |
51
|
|
|
protected $servers = []; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @var string |
55
|
|
|
*/ |
56
|
|
|
protected $collectionName = 'Cache'; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @var string |
60
|
|
|
*/ |
61
|
|
|
protected $databaseName = Driver::MONGODB_DEFAULT_DB_NAME; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @var array |
65
|
|
|
*/ |
66
|
|
|
protected $options = []; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @var array |
70
|
|
|
*/ |
71
|
|
|
protected $driverOptions = []; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @var string |
75
|
|
|
*/ |
76
|
|
|
protected $protocol = 'mongodb'; |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return string |
80
|
|
|
*/ |
81
|
|
|
public function getHost(): string |
82
|
|
|
{ |
83
|
|
|
return $this->host; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param string $host |
88
|
|
|
* @return self |
89
|
|
|
*/ |
90
|
|
|
public function setHost(string $host): self |
91
|
|
|
{ |
92
|
|
|
$this->host = $host; |
93
|
|
|
return $this; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @return int |
98
|
|
|
*/ |
99
|
|
|
public function getPort(): int |
100
|
|
|
{ |
101
|
|
|
return $this->port; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @param int $port |
106
|
|
|
* @return self |
107
|
|
|
*/ |
108
|
|
|
public function setPort(int $port): self |
109
|
|
|
{ |
110
|
|
|
$this->port = $port; |
111
|
|
|
return $this; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @return int |
116
|
|
|
*/ |
117
|
|
|
public function getTimeout(): int |
118
|
|
|
{ |
119
|
|
|
return $this->timeout; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @param int $timeout |
124
|
|
|
* @return self |
125
|
|
|
*/ |
126
|
|
|
public function setTimeout(int $timeout): self |
127
|
|
|
{ |
128
|
|
|
$this->timeout = $timeout; |
129
|
|
|
return $this; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @return string |
134
|
|
|
*/ |
135
|
|
|
public function getUsername(): string |
136
|
|
|
{ |
137
|
|
|
return $this->username; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @param string $username |
142
|
|
|
* @return self |
143
|
|
|
*/ |
144
|
|
|
public function setUsername(string $username): self |
145
|
|
|
{ |
146
|
|
|
$this->username = $username; |
147
|
|
|
return $this; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @return string |
152
|
|
|
*/ |
153
|
|
|
public function getPassword(): string |
154
|
|
|
{ |
155
|
|
|
return $this->password; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @param string $password |
160
|
|
|
* @return self |
161
|
|
|
*/ |
162
|
|
|
public function setPassword(string $password): self |
163
|
|
|
{ |
164
|
|
|
$this->password = $password; |
165
|
|
|
return $this; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @return array |
170
|
|
|
*/ |
171
|
|
|
public function getServers(): array |
172
|
|
|
{ |
173
|
|
|
return $this->servers; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* @param array $servers |
178
|
|
|
* @return self |
179
|
|
|
*/ |
180
|
|
|
public function setServers(array $servers): self |
181
|
|
|
{ |
182
|
|
|
$this->servers = $servers; |
183
|
|
|
return $this; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* @return string |
188
|
|
|
*/ |
189
|
|
|
public function getCollectionName(): string |
190
|
|
|
{ |
191
|
|
|
return $this->collectionName; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* @param string $collectionName |
196
|
|
|
* @return self |
197
|
|
|
*/ |
198
|
|
|
public function setCollectionName(string $collectionName): self |
199
|
|
|
{ |
200
|
|
|
$this->collectionName = $collectionName; |
201
|
|
|
return $this; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* @return string |
206
|
|
|
*/ |
207
|
|
|
public function getDatabaseName(): string |
208
|
|
|
{ |
209
|
|
|
return $this->databaseName; |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* @param string $databaseName |
214
|
|
|
* @return self |
215
|
|
|
*/ |
216
|
|
|
public function setDatabaseName(string $databaseName): self |
217
|
|
|
{ |
218
|
|
|
$this->databaseName = $databaseName; |
219
|
|
|
return $this; |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* @return array |
224
|
|
|
*/ |
225
|
|
|
public function getOptions(): array |
226
|
|
|
{ |
227
|
|
|
return $this->options; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* @see https://docs.mongodb.com/manual/reference/connection-string/#connections-connection-options |
232
|
|
|
* @param array $options |
233
|
|
|
* @return Config |
234
|
|
|
*/ |
235
|
|
|
public function setOptions(array $options): self |
236
|
|
|
{ |
237
|
|
|
$this->options = $options; |
238
|
|
|
return $this; |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
/** |
242
|
|
|
* @return array |
243
|
|
|
*/ |
244
|
|
|
public function getDriverOptions(): array |
245
|
|
|
{ |
246
|
|
|
return $this->driverOptions; |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
/** |
250
|
|
|
* @param array $driverOptions |
251
|
|
|
* @return self |
252
|
|
|
*/ |
253
|
|
|
public function setDriverOptions(array $driverOptions): self |
254
|
|
|
{ |
255
|
|
|
$this->driverOptions = $driverOptions; |
256
|
|
|
return $this; |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
/** |
260
|
|
|
* @return string |
261
|
|
|
*/ |
262
|
|
|
public function getProtocol(): string |
263
|
|
|
{ |
264
|
|
|
return $this->protocol; |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
/** |
268
|
|
|
* @param string $protocol |
269
|
|
|
* @return self |
270
|
|
|
*/ |
271
|
|
|
public function setProtocol(string $protocol): self |
272
|
|
|
{ |
273
|
|
|
$this->protocol = $protocol; |
274
|
|
|
return $this; |
275
|
|
|
} |
276
|
|
|
} |