|
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-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
20 * @version $Id: Storage.php 20096 2010-01-06 02:05:09Z bkarwin $ |
|
21 */ |
|
22 |
|
23 /** |
|
24 * @see Zend_Tool_Framework_Client_Storage_AdapterInterface |
|
25 */ |
|
26 require_once 'Zend/Tool/Framework/Client/Storage/AdapterInterface.php'; |
|
27 |
|
28 /** |
|
29 * @category Zend |
|
30 * @package Zend_Tool |
|
31 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
32 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
33 */ |
|
34 class Zend_Tool_Framework_Client_Storage |
|
35 { |
|
36 |
|
37 /** |
|
38 * @var Zend_Tool_Framework_Client_Storage_AdapterInterface |
|
39 */ |
|
40 protected $_adapter = null; |
|
41 |
|
42 public function __construct($options = array()) |
|
43 { |
|
44 if (isset($options['adapter'])) { |
|
45 $this->setAdapter($options['adapter']); |
|
46 } |
|
47 } |
|
48 |
|
49 public function setAdapter($adapter) |
|
50 { |
|
51 if (is_string($adapter)) { |
|
52 $storageAdapterClass = 'Zend_Tool_Framework_Client_Storage_' . ucfirst($adapter); |
|
53 Zend_Loader::loadClass($storageAdapterClass); |
|
54 $adapter = new $storageAdapterClass(); |
|
55 } |
|
56 $this->_adapter = $adapter; |
|
57 } |
|
58 |
|
59 public function isEnabled() |
|
60 { |
|
61 return ($this->_adapter instanceof Zend_Tool_Framework_Client_Storage_AdapterInterface); |
|
62 } |
|
63 |
|
64 public function put($name, $value) |
|
65 { |
|
66 if (!$this->_adapter) { |
|
67 return false; |
|
68 } |
|
69 |
|
70 $this->_adapter->put($name, $value); |
|
71 |
|
72 return $this; |
|
73 } |
|
74 |
|
75 public function get($name, $defaultValue = false) |
|
76 { |
|
77 if (!$this->_adapter) { |
|
78 return false; |
|
79 } |
|
80 |
|
81 if ($this->_adapter->has($name)) { |
|
82 return $this->_adapter->get($name); |
|
83 } else { |
|
84 return $defaultValue; |
|
85 } |
|
86 |
|
87 } |
|
88 |
|
89 public function has($name) |
|
90 { |
|
91 if (!$this->_adapter) { |
|
92 return false; |
|
93 } |
|
94 |
|
95 return $this->_adapter->has($name); |
|
96 } |
|
97 |
|
98 public function remove($name) |
|
99 { |
|
100 if (!$this->_adapter) { |
|
101 return false; |
|
102 } |
|
103 |
|
104 $this->_adapter->remove($name); |
|
105 |
|
106 return $this; |
|
107 } |
|
108 |
|
109 public function getStreamUri($name) |
|
110 { |
|
111 if (!$this->_adapter) { |
|
112 return false; |
|
113 } |
|
114 |
|
115 return $this->_adapter->getStreamUri($name); |
|
116 } |
|
117 } |