upgrade zend (#1559)
[openemr.git] / vendor / zendframework / zend-cache / src / Storage / Adapter / MemcachedOptions.php
blob9a1a5d2c9cf31e5e9ab96886f7fa5feed9debf71
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-2016 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 Memcached as MemcachedResource;
13 use Zend\Cache\Exception;
15 /**
16 * These are options specific to the Memcached adapter
18 class MemcachedOptions extends AdapterOptions
20 // @codingStandardsIgnoreStart
21 /**
22 * Prioritized properties ordered by prio to be set first
23 * in case a bulk of options sets set at once
25 * @var string[]
27 protected $__prioritizedProperties__ = ['resource_manager', 'resource_id'];
28 // @codingStandardsIgnoreEnd
30 /**
31 * The namespace separator
32 * @var string
34 protected $namespaceSeparator = ':';
36 /**
37 * The memcached resource manager
39 * @var null|MemcachedResourceManager
41 protected $resourceManager;
43 /**
44 * The resource id of the resource manager
46 * @var string
48 protected $resourceId = 'default';
50 /**
51 * Set namespace.
53 * The option Memcached::OPT_PREFIX_KEY will be used as the namespace.
54 * It can't be longer than 128 characters.
56 * @see AdapterOptions::setNamespace()
57 * @see MemcachedOptions::setPrefixKey()
59 public function setNamespace($namespace)
61 $namespace = (string) $namespace;
63 if (128 < strlen($namespace)) {
64 throw new Exception\InvalidArgumentException(sprintf(
65 '%s expects a prefix key of no longer than 128 characters',
66 __METHOD__
67 ));
70 return parent::setNamespace($namespace);
73 /**
74 * Set namespace separator
76 * @param string $namespaceSeparator
77 * @return MemcachedOptions
79 public function setNamespaceSeparator($namespaceSeparator)
81 $namespaceSeparator = (string) $namespaceSeparator;
82 if ($this->namespaceSeparator !== $namespaceSeparator) {
83 $this->triggerOptionEvent('namespace_separator', $namespaceSeparator);
84 $this->namespaceSeparator = $namespaceSeparator;
86 return $this;
89 /**
90 * Get namespace separator
92 * @return string
94 public function getNamespaceSeparator()
96 return $this->namespaceSeparator;
99 /**
100 * A memcached resource to share
102 * @param null|MemcachedResource $memcachedResource
103 * @return MemcachedOptions
104 * @deprecated Please use the resource manager instead
106 public function setMemcachedResource(MemcachedResource $memcachedResource = null)
108 trigger_error(
109 'This method is deprecated and will be removed in the feature'
110 . ', please use the resource manager instead',
111 E_USER_DEPRECATED
114 if ($memcachedResource !== null) {
115 $this->triggerOptionEvent('memcached_resource', $memcachedResource);
116 $resourceManager = $this->getResourceManager();
117 $resourceId = $this->getResourceId();
118 $resourceManager->setResource($resourceId, $memcachedResource);
120 return $this;
124 * Get memcached resource to share
126 * @return MemcachedResource
127 * @deprecated Please use the resource manager instead
129 public function getMemcachedResource()
131 trigger_error(
132 'This method is deprecated and will be removed in the feature'
133 . ', please use the resource manager instead',
134 E_USER_DEPRECATED
137 return $this->resourceManager->getResource($this->getResourceId());
141 * Set the memcached resource manager to use
143 * @param null|MemcachedResourceManager $resourceManager
144 * @return MemcachedOptions
146 public function setResourceManager(MemcachedResourceManager $resourceManager = null)
148 if ($this->resourceManager !== $resourceManager) {
149 $this->triggerOptionEvent('resource_manager', $resourceManager);
150 $this->resourceManager = $resourceManager;
152 return $this;
156 * Get the memcached resource manager
158 * @return MemcachedResourceManager
160 public function getResourceManager()
162 if (! $this->resourceManager) {
163 $this->resourceManager = new MemcachedResourceManager();
165 return $this->resourceManager;
169 * Get the memcached resource id
171 * @return string
173 public function getResourceId()
175 return $this->resourceId;
179 * Set the memcached resource id
181 * @param string $resourceId
182 * @return MemcachedOptions
184 public function setResourceId($resourceId)
186 $resourceId = (string) $resourceId;
187 if ($this->resourceId !== $resourceId) {
188 $this->triggerOptionEvent('resource_id', $resourceId);
189 $this->resourceId = $resourceId;
191 return $this;
195 * Get the persistent id
197 * @return string
199 public function getPersistentId()
201 return $this->getResourceManager()->getPersistentId($this->getResourceId());
205 * Set the persistent id
207 * @param string $persistentId
208 * @return MemcachedOptions
210 public function setPersistentId($persistentId)
212 $this->triggerOptionEvent('persistent_id', $persistentId);
213 $this->getResourceManager()->setPersistentId($this->getResourceId(), $persistentId);
214 return $this;
218 * Add a server to the list
220 * @param string $host
221 * @param int $port
222 * @param int $weight
223 * @return MemcachedOptions
224 * @deprecated Please use the resource manager instead
226 public function addServer($host, $port = 11211, $weight = 0)
228 trigger_error(
229 'This method is deprecated and will be removed in the feature'
230 . ', please use the resource manager instead',
231 E_USER_DEPRECATED
234 $this->getResourceManager()->addServer($this->getResourceId(), [
235 'host' => $host,
236 'port' => $port,
237 'weight' => $weight
240 return $this;
244 * Set a list of memcached servers to add on initialize
246 * @param string|array $servers list of servers
247 * @return MemcachedOptions
248 * @throws Exception\InvalidArgumentException
250 public function setServers($servers)
252 $this->getResourceManager()->setServers($this->getResourceId(), $servers);
253 return $this;
257 * Get Servers
259 * @return array
261 public function getServers()
263 return $this->getResourceManager()->getServers($this->getResourceId());
267 * Set libmemcached options
269 * @param array $libOptions
270 * @return MemcachedOptions
271 * @link http://php.net/manual/memcached.constants.php
273 public function setLibOptions(array $libOptions)
275 $this->getResourceManager()->setLibOptions($this->getResourceId(), $libOptions);
276 return $this;
280 * Set libmemcached option
282 * @param string|int $key
283 * @param mixed $value
284 * @return MemcachedOptions
285 * @link http://php.net/manual/memcached.constants.php
286 * @deprecated Please use lib_options or the resource manager instead
288 public function setLibOption($key, $value)
290 trigger_error(
291 'This method is deprecated and will be removed in the feature'
292 . ', please use "lib_options" or the resource manager instead',
293 E_USER_DEPRECATED
296 $this->getResourceManager()->setLibOption($this->getResourceId(), $key, $value);
297 return $this;
301 * Get libmemcached options
303 * @return array
304 * @link http://php.net/manual/memcached.constants.php
306 public function getLibOptions()
308 return $this->getResourceManager()->getLibOptions($this->getResourceId());
312 * Get libmemcached option
314 * @param string|int $key
315 * @return mixed
316 * @link http://php.net/manual/memcached.constants.php
317 * @deprecated Please use lib_options or the resource manager instead
319 public function getLibOption($key)
321 trigger_error(
322 'This method is deprecated and will be removed in the feature'
323 . ', please use "lib_options" or the resource manager instead',
324 E_USER_DEPRECATED
327 return $this->getResourceManager()->getLibOption($this->getResourceId(), $key);