Completed
Push — develop ( c0c47b...cc4ea9 )
by Siad
04:17
created

CouchbaseOptions::getUsername()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
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 62
    public function getNamespaceSeparator()
100
    {
101 62
        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 62
    public function getResourceManager()
127
    {
128 62
        if (!$this->resourceManager) {
129 62
            $this->resourceManager = new CouchbaseResourceManager();
130 62
        }
131
132 62
        return $this->resourceManager;
133
    }
134
135
    /**
136
     * Get the couchbase resource id.
137
     *
138
     * @return string
139
     */
140 62
    public function getResourceId()
141
    {
142 62
        return $this->resourceId;
143
    }
144
145
    /**
146
     * Set the couchbase resource id.
147
     *
148
     * @param string $resourceId
149
     *
150
     * @return CouchbaseOptions
151
     */
152 62
    public function setResourceId($resourceId)
153
    {
154 62
        $resourceId = (string) $resourceId;
155 62
        if ($this->resourceId !== $resourceId) {
156 62
            $this->triggerOptionEvent('resource_id', $resourceId);
157 62
            $this->resourceId = $resourceId;
158 62
        }
159
160 62
        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 getBucket()
217
    {
218
        return $this->getResourceManager()->getBucket($this->getResourceId());
219
    }
220
221
    /**
222
     * Set the persistent id.
223
     *
224
     * @param string $bucket
225
     *
226
     * @return CouchbaseOptions
227
     */
228
    public function setBucket($bucket)
229
    {
230
        $this->getResourceManager()->setBucket($this->getResourceId(), $bucket);
231
232
        return $this;
233
    }
234
235
    /**
236
     * Set a list of couchbase servers to add on initialize.
237
     *
238
     * @param string $server server
239
     *
240
     * @return CouchbaseOptions
241
     *
242
     * @throws Exception\InvalidArgumentException
243
     */
244
    public function setServer($server)
245
    {
246
        $this->getResourceManager()->setServer($this->getResourceId(), $server);
247
248
        return $this;
249
    }
250
251
    /**
252
     * Get Servers.
253
     *
254
     * @return array
255
     */
256
    public function getServer()
257
    {
258
        return $this->getResourceManager()->getServer($this->getResourceId());
259
    }
260
261
    /**
262
     * Set libmemcached options.
263
     *
264
     * @param array $libOptions
265
     *
266
     * @return CouchbaseOptions
267
     */
268 1
    public function setLibOptions(array $libOptions)
269
    {
270 1
        $this->getResourceManager()->setLibOptions($this->getResourceId(), $libOptions);
271
272
        return $this;
273
    }
274
275
    /**
276
     * Get libmemcached options.
277
     *
278
     * @return array
279
     */
280
    public function getLibOptions()
281
    {
282
        return $this->getResourceManager()->getLibOptions($this->getResourceId());
283
    }
284
}
285