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
|
|
|
* @return string |
75
|
|
|
*/ |
76
|
|
|
public function getHost(): string |
77
|
|
|
{ |
78
|
|
|
return $this->host; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param string $host |
83
|
|
|
* @return self |
84
|
|
|
*/ |
85
|
|
|
public function setHost(string $host): self |
86
|
|
|
{ |
87
|
|
|
$this->host = $host; |
88
|
|
|
return $this; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @return int |
93
|
|
|
*/ |
94
|
|
|
public function getPort(): int |
95
|
|
|
{ |
96
|
|
|
return $this->port; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @param int $port |
101
|
|
|
* @return self |
102
|
|
|
*/ |
103
|
|
|
public function setPort(int $port): self |
104
|
|
|
{ |
105
|
|
|
$this->port = $port; |
106
|
|
|
return $this; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @return int |
111
|
|
|
*/ |
112
|
|
|
public function getTimeout(): int |
113
|
|
|
{ |
114
|
|
|
return $this->timeout; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @param int $timeout |
119
|
|
|
* @return self |
120
|
|
|
*/ |
121
|
|
|
public function setTimeout(int $timeout): self |
122
|
|
|
{ |
123
|
|
|
$this->timeout = $timeout; |
124
|
|
|
return $this; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @return string |
129
|
|
|
*/ |
130
|
|
|
public function getUsername(): string |
131
|
|
|
{ |
132
|
|
|
return $this->username; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @param string $username |
137
|
|
|
* @return self |
138
|
|
|
*/ |
139
|
|
|
public function setUsername(string $username): self |
140
|
|
|
{ |
141
|
|
|
$this->username = $username; |
142
|
|
|
return $this; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @return string |
147
|
|
|
*/ |
148
|
|
|
public function getPassword(): string |
149
|
|
|
{ |
150
|
|
|
return $this->password; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @param string $password |
155
|
|
|
* @return self |
156
|
|
|
*/ |
157
|
|
|
public function setPassword(string $password): self |
158
|
|
|
{ |
159
|
|
|
$this->password = $password; |
160
|
|
|
return $this; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* @return array |
165
|
|
|
*/ |
166
|
|
|
public function getServers(): array |
167
|
|
|
{ |
168
|
|
|
return $this->servers; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @param array $servers |
173
|
|
|
* @return self |
174
|
|
|
*/ |
175
|
|
|
public function setServers(array $servers): self |
176
|
|
|
{ |
177
|
|
|
$this->servers = $servers; |
178
|
|
|
return $this; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* @return string |
183
|
|
|
*/ |
184
|
|
|
public function getCollectionName(): string |
185
|
|
|
{ |
186
|
|
|
return $this->collectionName; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* @param string $collectionName |
191
|
|
|
* @return self |
192
|
|
|
*/ |
193
|
|
|
public function setCollectionName(string $collectionName): self |
194
|
|
|
{ |
195
|
|
|
$this->collectionName = $collectionName; |
196
|
|
|
return $this; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* @return string |
201
|
|
|
*/ |
202
|
|
|
public function getDatabaseName(): string |
203
|
|
|
{ |
204
|
|
|
return $this->databaseName; |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* @param string $databaseName |
209
|
|
|
* @return self |
210
|
|
|
*/ |
211
|
|
|
public function setDatabaseName(string $databaseName): self |
212
|
|
|
{ |
213
|
|
|
$this->databaseName = $databaseName; |
214
|
|
|
return $this; |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* @return array |
219
|
|
|
*/ |
220
|
|
|
public function getOptions(): array |
221
|
|
|
{ |
222
|
|
|
return $this->options; |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* @see https://docs.mongodb.com/manual/reference/connection-string/#connections-connection-options |
227
|
|
|
* @param array $options |
228
|
|
|
* @return Config |
229
|
|
|
*/ |
230
|
|
|
public function setOptions(array $options): self |
231
|
|
|
{ |
232
|
|
|
$this->options = $options; |
233
|
|
|
return $this; |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
/** |
237
|
|
|
* @return array |
238
|
|
|
*/ |
239
|
|
|
public function getDriverOptions(): array |
240
|
|
|
{ |
241
|
|
|
return $this->driverOptions; |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
/** |
245
|
|
|
* @param array $driverOptions |
246
|
|
|
* @return self |
247
|
|
|
*/ |
248
|
|
|
public function setDriverOptions(array $driverOptions): self |
249
|
|
|
{ |
250
|
|
|
$this->driverOptions = $driverOptions; |
251
|
|
|
return $this; |
252
|
|
|
} |
253
|
|
|
} |