Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / Cache / Storage / Adapter / RedisOptions.php
blob9cd4ad0f3b2c2aa5da100ec5bd936aa8673d04d5
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
10 namespace Zend\Cache\Storage\Adapter;
12 use Redis as RedisResource;
13 use Zend\Cache\Exception;
14 use Zend\Cache\Storage\Adapter\AdapterOptions;
16 class RedisOptions extends AdapterOptions
18 /**
19 * The namespace separator
20 * @var string
22 protected $namespaceSeparator = ':';
24 /**
25 * The redis resource manager
27 * @var null|RedisResourceManager
29 protected $resourceManager;
31 /**
32 * The resource id of the resource manager
34 * @var string
36 protected $resourceId = 'default';
38 /**
39 * Set namespace.
41 * The option Redis::OPT_PREFIX will be used as the namespace.
42 * It can't be longer than 128 characters.
44 * @param string $namespace Prefix for each key stored in redis
45 * @return \Zend\Cache\Storage\Adapter\RedisOptions
47 * @see AdapterOptions::setNamespace()
48 * @see RedisOptions::setPrefixKey()
50 public function setNamespace($namespace)
52 $namespace = (string) $namespace;
54 if (128 < strlen($namespace)) {
55 throw new Exception\InvalidArgumentException(sprintf(
56 '%s expects a prefix key of no longer than 128 characters',
57 __METHOD__
58 ));
61 return parent::setNamespace($namespace);
64 /**
65 * Set namespace separator
67 * @param string $namespaceSeparator
68 * @return RedisOptions
70 public function setNamespaceSeparator($namespaceSeparator)
72 $namespaceSeparator = (string) $namespaceSeparator;
73 if ($this->namespaceSeparator !== $namespaceSeparator) {
74 $this->triggerOptionEvent('namespace_separator', $namespaceSeparator);
75 $this->namespaceSeparator = $namespaceSeparator;
77 return $this;
80 /**
81 * Get namespace separator
83 * @return string
85 public function getNamespaceSeparator()
87 return $this->namespaceSeparator;
90 /**
91 * Set the redis resource manager to use
93 * @param null|RedisResourceManager $resourceManager
94 * @return RedisOptions
96 public function setResourceManager(RedisResourceManager $resourceManager = null)
98 if ($this->resourceManager !== $resourceManager) {
99 $this->triggerOptionEvent('resource_manager', $resourceManager);
100 $this->resourceManager = $resourceManager;
102 return $this;
106 * Get the redis resource manager
108 * @return RedisResourceManager
110 public function getResourceManager()
112 if (!$this->resourceManager) {
113 $this->resourceManager = new RedisResourceManager();
115 return $this->resourceManager;
119 * Get the redis resource id
121 * @return string
123 public function getResourceId()
125 return $this->resourceId;
129 * Set the redis resource id
131 * @param string $resourceId
132 * @return RedisOptions
134 public function setResourceId($resourceId)
136 $resourceId = (string) $resourceId;
137 if ($this->resourceId !== $resourceId) {
138 $this->triggerOptionEvent('resource_id', $resourceId);
139 $this->resourceId = $resourceId;
141 return $this;
145 * Get the persistent id
147 * @return string
149 public function getPersistentId()
151 return $this->getResourceManager()->getPersistentId($this->getResourceId());
155 * Set the persistent id
157 * @param string $persistentId
158 * @return RedisOptions
160 public function setPersistentId($persistentId)
162 $this->triggerOptionEvent('persistent_id', $persistentId);
163 $this->getResourceManager()->setPersistentId($this->getResourceId(), $persistentId);
164 return $this;
168 * Set redis options
170 * @param array $libOptions
171 * @return RedisOptions
172 * @link http://github.com/nicolasff/phpredis#setoption
174 public function setLibOptions(array $libOptions)
176 $this->triggerOptionEvent('lib_option', $libOptions);
177 $this->getResourceManager()->setLibOptions($this->getResourceId(), $libOptions);
178 return $this;
182 * Get redis options
184 * @return array
185 * @link http://github.com/nicolasff/phpredis#setoption
187 public function getLibOptions()
189 return $this->getResourceManager()->getLibOptions($this->getResourceId());
193 * Set server
195 * Server can be described as follows:
196 * - URI: /path/to/sock.sock
197 * - Assoc: array('host' => <host>[, 'port' => <port>[, 'timeout' => <timeout>]])
198 * - List: array(<host>[, <port>, [, <timeout>]])
200 * @param string|array $server
202 * @return RedisOptions
204 public function setServer($server)
206 $this->getResourceManager()->setServer($this->getResourceId(), $server);
207 return $this;
211 * Get server
213 * @return array array('host' => <host>[, 'port' => <port>[, 'timeout' => <timeout>]])
215 public function getServer()
217 return $this->getResourceManager()->getServer($this->getResourceId());
221 * Set resource database number
223 * @param int $database Database number
225 * @return RedisOptions
227 public function setDatabase($database)
229 $this->getResourceManager()->setDatabase($this->getResourceId(), $database);
230 return $this;
234 * Get resource database number
236 * @return int Database number
238 public function getDatabase()
240 return $this->getResourceManager()->getDatabase($this->getResourceId());
244 * Set resource password
246 * @param string $password Password
248 * @return RedisOptions
250 public function setPassword($password)
252 $this->getResourceManager()->setPassword($this->getResourceId(), $password);
253 return $this;
257 * Get resource password
259 * @return string
261 public function getPassword()
263 return $this->getResourceManager()->getPassword($this->getResourceId());