Storage.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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-2009 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-2009 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(Zend_Tool_Framework_Client_Storage_AdapterInterface $adapter)
  45. {
  46. $this->_adapter = $adapter;
  47. }
  48. public function isEnabled()
  49. {
  50. return ($this->_adapter instanceof Zend_Tool_Framework_Client_Storage_AdapterInterface);
  51. }
  52. public function put($name, $value)
  53. {
  54. if (!$this->_adapter) {
  55. return false;
  56. }
  57. $this->_adapter->put($name, $value);
  58. return $this;
  59. }
  60. public function get($name, $defaultValue = false)
  61. {
  62. if (!$this->_adapter) {
  63. return false;
  64. }
  65. if ($this->_adapter->has($name)) {
  66. return $this->_adapter->get($name);
  67. } else {
  68. return $defaultValue;
  69. }
  70. }
  71. public function has($name)
  72. {
  73. if (!$this->_adapter) {
  74. return false;
  75. }
  76. return $this->_adapter->has($name);
  77. }
  78. public function remove($name)
  79. {
  80. if (!$this->_adapter) {
  81. return false;
  82. }
  83. $this->_adapter->remove($name);
  84. return $this;
  85. }
  86. }