PageRenderTime 42ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/monica/monica/vendor/zendframework/zendframework/library/Zend/Cache/Storage/Adapter/MemcachedOptions.php

https://bitbucket.org/alexandretaz/maniac_divers
PHP | 319 lines | 147 code | 31 blank | 141 comment | 6 complexity | 19fc7d3ffa895133fbaa54d11a15f4fc MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /**
  3. * Zend Framework (http://framework.zend.com/)
  4. *
  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. */
  9. namespace Zend\Cache\Storage\Adapter;
  10. use Memcached as MemcachedResource;
  11. use Zend\Cache\Exception;
  12. /**
  13. * These are options specific to the APC adapter
  14. */
  15. class MemcachedOptions extends AdapterOptions
  16. {
  17. /**
  18. * The namespace separator
  19. * @var string
  20. */
  21. protected $namespaceSeparator = ':';
  22. /**
  23. * The memcached resource manager
  24. *
  25. * @var null|MemcachedResourceManager
  26. */
  27. protected $resourceManager;
  28. /**
  29. * The resource id of the resource manager
  30. *
  31. * @var string
  32. */
  33. protected $resourceId = 'default';
  34. /**
  35. * Set namespace.
  36. *
  37. * The option Memcached::OPT_PREFIX_KEY will be used as the namespace.
  38. * It can't be longer than 128 characters.
  39. *
  40. * @see AdapterOptions::setNamespace()
  41. * @see MemcachedOptions::setPrefixKey()
  42. */
  43. public function setNamespace($namespace)
  44. {
  45. $namespace = (string) $namespace;
  46. if (128 < strlen($namespace)) {
  47. throw new Exception\InvalidArgumentException(sprintf(
  48. '%s expects a prefix key of no longer than 128 characters',
  49. __METHOD__
  50. ));
  51. }
  52. return parent::setNamespace($namespace);
  53. }
  54. /**
  55. * Set namespace separator
  56. *
  57. * @param string $namespaceSeparator
  58. * @return MemcachedOptions
  59. */
  60. public function setNamespaceSeparator($namespaceSeparator)
  61. {
  62. $namespaceSeparator = (string) $namespaceSeparator;
  63. if ($this->namespaceSeparator !== $namespaceSeparator) {
  64. $this->triggerOptionEvent('namespace_separator', $namespaceSeparator);
  65. $this->namespaceSeparator = $namespaceSeparator;
  66. }
  67. return $this;
  68. }
  69. /**
  70. * Get namespace separator
  71. *
  72. * @return string
  73. */
  74. public function getNamespaceSeparator()
  75. {
  76. return $this->namespaceSeparator;
  77. }
  78. /**
  79. * A memcached resource to share
  80. *
  81. * @param null|MemcachedResource $memcachedResource
  82. * @return MemcachedOptions
  83. * @deprecated Please use the resource manager instead
  84. */
  85. public function setMemcachedResource(MemcachedResource $memcachedResource = null)
  86. {
  87. trigger_error(
  88. 'This method is deprecated and will be removed in the feature'
  89. . ', please use the resource manager instead',
  90. E_USER_DEPRECATED
  91. );
  92. if ($memcachedResource !== null) {
  93. $this->triggerOptionEvent('memcached_resource', $memcachedResource);
  94. $resourceManager = $this->getResourceManager();
  95. $resourceId = $this->getResourceId();
  96. $resourceManager->setResource($resourceId, $memcachedResource);
  97. }
  98. return $this;
  99. }
  100. /**
  101. * Get memcached resource to share
  102. *
  103. * @return MemcachedResource
  104. * @deprecated Please use the resource manager instead
  105. */
  106. public function getMemcachedResource()
  107. {
  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
  112. );
  113. return $this->resourceManager->getResource($this->getResourceId());
  114. }
  115. /**
  116. * Set the memcached resource manager to use
  117. *
  118. * @param null|MemcachedResourceManager $resourceManager
  119. * @return MemcachedOptions
  120. */
  121. public function setResourceManager(MemcachedResourceManager $resourceManager = null)
  122. {
  123. if ($this->resourceManager !== $resourceManager) {
  124. $this->triggerOptionEvent('resource_manager', $resourceManager);
  125. $this->resourceManager = $resourceManager;
  126. }
  127. return $this;
  128. }
  129. /**
  130. * Get the memcached resource manager
  131. *
  132. * @return MemcachedResourceManager
  133. */
  134. public function getResourceManager()
  135. {
  136. if (!$this->resourceManager) {
  137. $this->resourceManager = new MemcachedResourceManager();
  138. }
  139. return $this->resourceManager;
  140. }
  141. /**
  142. * Get the memcached resource id
  143. *
  144. * @return string
  145. */
  146. public function getResourceId()
  147. {
  148. return $this->resourceId;
  149. }
  150. /**
  151. * Set the memcached resource id
  152. *
  153. * @param string $resourceId
  154. * @return MemcachedOptions
  155. */
  156. public function setResourceId($resourceId)
  157. {
  158. $resourceId = (string) $resourceId;
  159. if ($this->resourceId !== $resourceId) {
  160. $this->triggerOptionEvent('resource_id', $resourceId);
  161. $this->resourceId = $resourceId;
  162. }
  163. return $this;
  164. }
  165. /**
  166. * Get the persistent id
  167. *
  168. * @return string
  169. */
  170. public function getPersistentId()
  171. {
  172. return $this->getResourceManager()->getPersistentId($this->getResourceId());
  173. }
  174. /**
  175. * Set the persistent id
  176. *
  177. * @param string $persistentId
  178. * @return MemcachedOptions
  179. */
  180. public function setPersistentId($persistentId)
  181. {
  182. $this->triggerOptionEvent('persistent_id', $persistentId);
  183. $this->getResourceManager()->setPersistentId($this->getPersistentId(), $persistentId);
  184. return $this;
  185. }
  186. /**
  187. * Add a server to the list
  188. *
  189. * @param string $host
  190. * @param int $port
  191. * @param int $weight
  192. * @return MemcachedOptions
  193. * @deprecated Please use the resource manager instead
  194. */
  195. public function addServer($host, $port = 11211, $weight = 0)
  196. {
  197. trigger_error(
  198. 'This method is deprecated and will be removed in the feature'
  199. . ', please use the resource manager instead',
  200. E_USER_DEPRECATED
  201. );
  202. $this->getResourceManager()->addServer($this->getResourceId(), array(
  203. 'host' => $host,
  204. 'port' => $port,
  205. 'weight' => $weight
  206. ));
  207. return $this;
  208. }
  209. /**
  210. * Set a list of memcached servers to add on initialize
  211. *
  212. * @param string|array $servers list of servers
  213. * @return MemcachedOptions
  214. * @throws Exception\InvalidArgumentException
  215. */
  216. public function setServers($servers)
  217. {
  218. $this->getResourceManager()->setServers($this->getResourceId(), $servers);
  219. return $this;
  220. }
  221. /**
  222. * Get Servers
  223. *
  224. * @return array
  225. */
  226. public function getServers()
  227. {
  228. return $this->getResourceManager()->getServers($this->getResourceId());
  229. }
  230. /**
  231. * Set libmemcached options
  232. *
  233. * @param array $libOptions
  234. * @return MemcachedOptions
  235. * @link http://php.net/manual/memcached.constants.php
  236. */
  237. public function setLibOptions(array $libOptions)
  238. {
  239. $this->getResourceManager()->setLibOptions($this->getResourceId(), $libOptions);
  240. return $this;
  241. }
  242. /**
  243. * Set libmemcached option
  244. *
  245. * @param string|int $key
  246. * @param mixed $value
  247. * @return MemcachedOptions
  248. * @link http://php.net/manual/memcached.constants.php
  249. * @deprecated Please use lib_options or the resource manager instead
  250. */
  251. public function setLibOption($key, $value)
  252. {
  253. trigger_error(
  254. 'This method is deprecated and will be removed in the feature'
  255. . ', please use "lib_options" or the resource manager instead',
  256. E_USER_DEPRECATED
  257. );
  258. $this->getResourceManager()->setLibOption($this->getResourceId(), $key, $value);
  259. return $this;
  260. }
  261. /**
  262. * Get libmemcached options
  263. *
  264. * @return array
  265. * @link http://php.net/manual/memcached.constants.php
  266. */
  267. public function getLibOptions()
  268. {
  269. return $this->getResourceManager()->getLibOptions($this->getResourceId());
  270. }
  271. /**
  272. * Get libmemcached option
  273. *
  274. * @param string|int $key
  275. * @return mixed
  276. * @link http://php.net/manual/memcached.constants.php
  277. * @deprecated Please use lib_options or the resource manager instead
  278. */
  279. public function getLibOption($key)
  280. {
  281. trigger_error(
  282. 'This method is deprecated and will be removed in the feature'
  283. . ', please use "lib_options" or the resource manager instead',
  284. E_USER_DEPRECATED
  285. );
  286. return $this->getResourceManager()->getLibOption($this->getResourceId(), $key);
  287. }
  288. }