Storage.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Tool
  17. * @subpackage Framework
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * @see Zend_Tool_Framework_Client_Storage_AdapterInterface
  24. */
  25. require_once 'Zend/Tool/Framework/Client/Storage/AdapterInterface.php';
  26. /**
  27. * @category Zend
  28. * @package Zend_Tool
  29. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  30. * @license http://framework.zend.com/license/new-bsd New BSD License
  31. */
  32. class Zend_Tool_Framework_Client_Storage
  33. {
  34. /**
  35. * @var Zend_Tool_Framework_Client_Storage_AdapterInterface
  36. */
  37. protected $_adapter = null;
  38. public function __construct($options = array())
  39. {
  40. if (isset($options['adapter'])) {
  41. $this->setAdapter($options['adapter']);
  42. }
  43. }
  44. public function setAdapter($adapter)
  45. {
  46. if (is_string($adapter)) {
  47. $storageAdapterClass = 'Zend_Tool_Framework_Client_Storage_' . ucfirst($adapter);
  48. Zend_Loader::loadClass($storageAdapterClass);
  49. $adapter = new $storageAdapterClass();
  50. }
  51. $this->_adapter = $adapter;
  52. }
  53. public function isEnabled()
  54. {
  55. return ($this->_adapter instanceof Zend_Tool_Framework_Client_Storage_AdapterInterface);
  56. }
  57. public function put($name, $value)
  58. {
  59. if (!$this->_adapter) {
  60. return false;
  61. }
  62. $this->_adapter->put($name, $value);
  63. return $this;
  64. }
  65. public function get($name, $defaultValue = false)
  66. {
  67. if (!$this->_adapter) {
  68. return false;
  69. }
  70. if ($this->_adapter->has($name)) {
  71. return $this->_adapter->get($name);
  72. } else {
  73. return $defaultValue;
  74. }
  75. }
  76. public function has($name)
  77. {
  78. if (!$this->_adapter) {
  79. return false;
  80. }
  81. return $this->_adapter->has($name);
  82. }
  83. public function remove($name)
  84. {
  85. if (!$this->_adapter) {
  86. return false;
  87. }
  88. $this->_adapter->remove($name);
  89. return $this;
  90. }
  91. public function getStreamUri($name)
  92. {
  93. if (!$this->_adapter) {
  94. return false;
  95. }
  96. return $this->_adapter->getStreamUri($name);
  97. }
  98. }