|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* zf-couchbase2. |
|
4
|
|
|
* |
|
5
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
6
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
7
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
8
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
9
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
10
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|
11
|
|
|
* SOFTWARE. |
|
12
|
|
|
* |
|
13
|
|
|
* @copyright 2015 MehrAlsNix (http://www.mehralsnix.de) |
|
14
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
|
15
|
|
|
* |
|
16
|
|
|
* @link http://github.com/MehrAlsNix/zf-couchbase2 |
|
17
|
|
|
*/ |
|
18
|
|
|
namespace MehrAlsNix\ZF\Cache\Storage\Adapter; |
|
19
|
|
|
|
|
20
|
|
|
use Zend\Cache\Exception; |
|
21
|
|
|
use Zend\Cache\Storage\Adapter\AdapterOptions; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Class CouchbaseOptions. |
|
25
|
|
|
*/ |
|
26
|
|
|
class CouchbaseOptions extends AdapterOptions |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* The namespace separator. |
|
30
|
|
|
* |
|
31
|
|
|
* @var string |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $namespaceSeparator = ':'; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* The couchbase resource manager. |
|
37
|
|
|
* |
|
38
|
|
|
* @var null|CouchbaseResourceManager |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $resourceManager; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* The resource id of the resource manager. |
|
44
|
|
|
* |
|
45
|
|
|
* @var string |
|
46
|
|
|
*/ |
|
47
|
|
|
protected $resourceId = 'default'; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Set namespace. |
|
51
|
|
|
* |
|
52
|
|
|
* |
|
53
|
|
|
* @see AdapterOptions::setNamespace() |
|
54
|
|
|
* @see CouchbaseOptions::setPrefixKey() |
|
55
|
|
|
* |
|
56
|
|
|
* @param string $namespace |
|
57
|
|
|
* |
|
58
|
|
|
* @return AdapterOptions |
|
59
|
|
|
* |
|
60
|
|
|
* @throws Exception\InvalidArgumentException |
|
61
|
|
|
*/ |
|
62
|
6 |
|
public function setNamespace($namespace) |
|
63
|
|
|
{ |
|
64
|
6 |
|
$namespace = (string) $namespace; |
|
65
|
|
|
|
|
66
|
6 |
|
if (128 < strlen($namespace)) { |
|
67
|
|
|
throw new Exception\InvalidArgumentException(sprintf( |
|
68
|
|
|
'%s expects a prefix key of no longer than 128 characters', |
|
69
|
|
|
__METHOD__ |
|
70
|
|
|
)); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
6 |
|
return parent::setNamespace($namespace); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Set namespace separator. |
|
78
|
|
|
* |
|
79
|
|
|
* @param string $namespaceSeparator |
|
80
|
|
|
* |
|
81
|
|
|
* @return CouchbaseOptions |
|
82
|
|
|
*/ |
|
83
|
1 |
|
public function setNamespaceSeparator($namespaceSeparator) |
|
84
|
|
|
{ |
|
85
|
1 |
|
$namespaceSeparator = (string) $namespaceSeparator; |
|
86
|
1 |
|
if ($this->namespaceSeparator !== $namespaceSeparator) { |
|
87
|
|
|
$this->triggerOptionEvent('namespace_separator', $namespaceSeparator); |
|
88
|
|
|
$this->namespaceSeparator = $namespaceSeparator; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
1 |
|
return $this; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Get namespace separator. |
|
96
|
|
|
* |
|
97
|
|
|
* @return string |
|
98
|
|
|
*/ |
|
99
|
61 |
|
public function getNamespaceSeparator() |
|
100
|
|
|
{ |
|
101
|
61 |
|
return $this->namespaceSeparator; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Set the couchbase resource manager to use. |
|
106
|
|
|
* |
|
107
|
|
|
* @param null|CouchbaseResourceManager $resourceManager |
|
108
|
|
|
* |
|
109
|
|
|
* @return CouchbaseOptions |
|
110
|
|
|
*/ |
|
111
|
1 |
|
public function setResourceManager(CouchbaseResourceManager $resourceManager = null) |
|
112
|
|
|
{ |
|
113
|
1 |
|
if ($this->resourceManager !== $resourceManager) { |
|
114
|
|
|
$this->triggerOptionEvent('resource_manager', $resourceManager); |
|
115
|
|
|
$this->resourceManager = $resourceManager; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
1 |
|
return $this; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* Get the couchbase resource manager. |
|
123
|
|
|
* |
|
124
|
|
|
* @return CouchbaseResourceManager |
|
125
|
|
|
*/ |
|
126
|
61 |
|
public function getResourceManager() |
|
127
|
|
|
{ |
|
128
|
61 |
|
if (!$this->resourceManager) { |
|
129
|
61 |
|
$this->resourceManager = new CouchbaseResourceManager(); |
|
130
|
61 |
|
} |
|
131
|
|
|
|
|
132
|
61 |
|
return $this->resourceManager; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* Get the couchbase resource id. |
|
137
|
|
|
* |
|
138
|
|
|
* @return string |
|
139
|
|
|
*/ |
|
140
|
61 |
|
public function getResourceId() |
|
141
|
|
|
{ |
|
142
|
61 |
|
return $this->resourceId; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* Set the couchbase resource id. |
|
147
|
|
|
* |
|
148
|
|
|
* @param string $resourceId |
|
149
|
|
|
* |
|
150
|
|
|
* @return CouchbaseOptions |
|
151
|
|
|
*/ |
|
152
|
61 |
|
public function setResourceId($resourceId) |
|
153
|
|
|
{ |
|
154
|
61 |
|
$resourceId = (string) $resourceId; |
|
155
|
61 |
|
if ($this->resourceId !== $resourceId) { |
|
156
|
61 |
|
$this->triggerOptionEvent('resource_id', $resourceId); |
|
157
|
61 |
|
$this->resourceId = $resourceId; |
|
158
|
61 |
|
} |
|
159
|
|
|
|
|
160
|
61 |
|
return $this; |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* Get the persistent id. |
|
165
|
|
|
* |
|
166
|
|
|
* @return string |
|
167
|
|
|
*/ |
|
168
|
|
|
public function getPassword() |
|
169
|
|
|
{ |
|
170
|
|
|
return $this->getResourceManager()->getPassword($this->getResourceId()); |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
/** |
|
174
|
|
|
* Set the persistent id. |
|
175
|
|
|
* |
|
176
|
|
|
* @param string $password |
|
177
|
|
|
* |
|
178
|
|
|
* @return CouchbaseOptions |
|
179
|
|
|
*/ |
|
180
|
|
|
public function setPassword($password) |
|
181
|
|
|
{ |
|
182
|
|
|
$this->getResourceManager()->setPassword($this->getResourceId(), $password); |
|
183
|
|
|
|
|
184
|
|
|
return $this; |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
/** |
|
188
|
|
|
* Get the persistent id. |
|
189
|
|
|
* |
|
190
|
|
|
* @return string |
|
191
|
|
|
*/ |
|
192
|
|
|
public function getUsername() |
|
193
|
|
|
{ |
|
194
|
|
|
return $this->getResourceManager()->getUsername($this->getResourceId()); |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
/** |
|
198
|
|
|
* Set the persistent id. |
|
199
|
|
|
* |
|
200
|
|
|
* @param string $username |
|
201
|
|
|
* |
|
202
|
|
|
* @return CouchbaseOptions |
|
203
|
|
|
*/ |
|
204
|
|
|
public function setUsername($username) |
|
205
|
|
|
{ |
|
206
|
|
|
$this->getResourceManager()->setUsername($this->getResourceId(), $username); |
|
207
|
|
|
|
|
208
|
|
|
return $this; |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
/** |
|
212
|
|
|
* Get the persistent id. |
|
213
|
|
|
* |
|
214
|
|
|
* @return string |
|
215
|
|
|
*/ |
|
216
|
|
|
public function getEncoder() |
|
217
|
|
|
{ |
|
218
|
|
|
return $this->getResourceManager()->getEncoder($this->getResourceId()); |
|
219
|
|
|
} |
|
220
|
|
|
|
|
221
|
|
|
/** |
|
222
|
|
|
* Set the persistent id. |
|
223
|
|
|
* |
|
224
|
|
|
* @param string $encoder |
|
225
|
|
|
* |
|
226
|
|
|
* @return CouchbaseOptions |
|
227
|
|
|
*/ |
|
228
|
|
|
public function setEncoder($encoder) |
|
229
|
|
|
{ |
|
230
|
|
|
$this->getResourceManager()->setEncoder($this->getResourceId(), $encoder); |
|
231
|
|
|
|
|
232
|
|
|
return $this; |
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
|
|
/** |
|
236
|
|
|
* Get the persistent id. |
|
237
|
|
|
* |
|
238
|
|
|
* @return string |
|
239
|
|
|
*/ |
|
240
|
|
|
public function getDecoder() |
|
241
|
|
|
{ |
|
242
|
|
|
return $this->getResourceManager()->getDecoder($this->getResourceId()); |
|
243
|
|
|
} |
|
244
|
|
|
|
|
245
|
|
|
/** |
|
246
|
|
|
* Set the persistent id. |
|
247
|
|
|
* |
|
248
|
|
|
* @param string $decoder |
|
249
|
|
|
* |
|
250
|
|
|
* @return CouchbaseOptions |
|
251
|
|
|
*/ |
|
252
|
|
|
public function setDecoder($decoder) |
|
253
|
|
|
{ |
|
254
|
|
|
$this->getResourceManager()->setUsername($this->getResourceId(), $decoder); |
|
255
|
|
|
|
|
256
|
|
|
return $this; |
|
257
|
|
|
} |
|
258
|
|
|
|
|
259
|
|
|
/** |
|
260
|
|
|
* Get the persistent id. |
|
261
|
|
|
* |
|
262
|
|
|
* @return string |
|
263
|
|
|
*/ |
|
264
|
|
|
public function getBucket() |
|
265
|
|
|
{ |
|
266
|
|
|
return $this->getResourceManager()->getBucket($this->getResourceId()); |
|
267
|
|
|
} |
|
268
|
|
|
|
|
269
|
|
|
/** |
|
270
|
|
|
* Set the persistent id. |
|
271
|
|
|
* |
|
272
|
|
|
* @param string $bucket |
|
273
|
|
|
* |
|
274
|
|
|
* @return CouchbaseOptions |
|
275
|
|
|
*/ |
|
276
|
|
|
public function setBucket($bucket) |
|
277
|
|
|
{ |
|
278
|
|
|
$this->getResourceManager()->setBucket($this->getResourceId(), $bucket); |
|
279
|
|
|
|
|
280
|
|
|
return $this; |
|
281
|
|
|
} |
|
282
|
|
|
|
|
283
|
|
|
/** |
|
284
|
|
|
* Set a list of couchbase servers to add on initialize. |
|
285
|
|
|
* |
|
286
|
|
|
* @param string $server server |
|
287
|
|
|
* |
|
288
|
|
|
* @return CouchbaseOptions |
|
289
|
|
|
* |
|
290
|
|
|
* @throws Exception\InvalidArgumentException |
|
291
|
|
|
*/ |
|
292
|
|
|
public function setServer($server) |
|
293
|
|
|
{ |
|
294
|
|
|
$this->getResourceManager()->setServer($this->getResourceId(), $server); |
|
295
|
|
|
|
|
296
|
|
|
return $this; |
|
297
|
|
|
} |
|
298
|
|
|
|
|
299
|
|
|
/** |
|
300
|
|
|
* Get Servers. |
|
301
|
|
|
* |
|
302
|
|
|
* @return array |
|
303
|
|
|
*/ |
|
304
|
|
|
public function getServer() |
|
305
|
|
|
{ |
|
306
|
|
|
return $this->getResourceManager()->getServer($this->getResourceId()); |
|
307
|
|
|
} |
|
308
|
|
|
} |
|
309
|
|
|
|