|
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: Dynamic.php 20096 2010-01-06 02:05:09Z bkarwin $ |
|
21 */ |
|
22 |
|
23 /** |
|
24 * @see Zend_Tool_Framework_Metadata_Interface |
|
25 */ |
|
26 require_once 'Zend/Tool/Framework/Metadata/Interface.php'; |
|
27 |
|
28 /** |
|
29 * @see Zend_Tool_Framework_Metadata_Attributable |
|
30 */ |
|
31 require_once 'Zend/Tool/Framework/Metadata/Attributable.php'; |
|
32 |
|
33 /** |
|
34 * @category Zend |
|
35 * @package Zend_Tool |
|
36 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
37 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
38 */ |
|
39 class Zend_Tool_Framework_Metadata_Dynamic |
|
40 implements Zend_Tool_Framework_Metadata_Interface, Zend_Tool_Framework_Metadata_Attributable |
|
41 { |
|
42 |
|
43 /** |
|
44 * @var string |
|
45 */ |
|
46 protected $_type = 'Dynamic'; |
|
47 |
|
48 /** |
|
49 * @var string |
|
50 */ |
|
51 protected $_name = null; |
|
52 |
|
53 /** |
|
54 * @var string |
|
55 */ |
|
56 protected $_value = null; |
|
57 |
|
58 /** |
|
59 * @var array |
|
60 */ |
|
61 protected $_dynamicAttributes = array(); |
|
62 |
|
63 public function __construct($options = array()) |
|
64 { |
|
65 if ($options) { |
|
66 $this->setOptions($options); |
|
67 } |
|
68 } |
|
69 |
|
70 public function setOptions(Array $options = array()) |
|
71 { |
|
72 foreach ($options as $optName => $optValue) { |
|
73 $methodName = 'set' . $optName; |
|
74 $this->{$methodName}($optValue); |
|
75 } |
|
76 } |
|
77 |
|
78 /** |
|
79 * setType() |
|
80 * |
|
81 * @param $type |
|
82 * @return Zend_Tool_Framework_Metadata_Dynamic |
|
83 */ |
|
84 public function setType($type) |
|
85 { |
|
86 $this->_type = $type; |
|
87 return $this; |
|
88 } |
|
89 |
|
90 /** |
|
91 * getType() |
|
92 * |
|
93 * The type of metadata this describes |
|
94 * |
|
95 * @return string |
|
96 */ |
|
97 public function getType() |
|
98 { |
|
99 return $this->_type; |
|
100 } |
|
101 |
|
102 /** |
|
103 * setName() |
|
104 * |
|
105 * @param $name |
|
106 * @return Zend_Tool_Framework_Metadata_Dynamic |
|
107 */ |
|
108 public function setName($name) |
|
109 { |
|
110 $this->_name = $name; |
|
111 return $this; |
|
112 } |
|
113 |
|
114 /** |
|
115 * getName() |
|
116 * |
|
117 * Metadata name |
|
118 * |
|
119 * @return string |
|
120 */ |
|
121 public function getName() |
|
122 { |
|
123 return $this->_name; |
|
124 } |
|
125 |
|
126 /** |
|
127 * setValue() |
|
128 * |
|
129 * @param $value |
|
130 * @return Zend_Tool_Framework_Metadata_Dynamic |
|
131 */ |
|
132 public function setValue($value) |
|
133 { |
|
134 $this->_value = $value; |
|
135 return $this; |
|
136 } |
|
137 |
|
138 /** |
|
139 * getValue() |
|
140 * |
|
141 * Metadata Value |
|
142 * |
|
143 * @return string |
|
144 */ |
|
145 public function getValue() |
|
146 { |
|
147 return $this->_value; |
|
148 } |
|
149 |
|
150 public function getAttributes() |
|
151 { |
|
152 return $this->_dynamicAttributes; |
|
153 } |
|
154 |
|
155 /** |
|
156 * __isset() |
|
157 * |
|
158 * Check if an attrbute is set |
|
159 * |
|
160 * @param string $name |
|
161 * @return bool |
|
162 */ |
|
163 public function __isset($name) |
|
164 { |
|
165 return isset($this->_dynamicAttributes[$name]); |
|
166 } |
|
167 |
|
168 /** |
|
169 * __unset() |
|
170 * |
|
171 * @param string $name |
|
172 * @return null |
|
173 */ |
|
174 public function __unset($name) |
|
175 { |
|
176 unset($this->_dynamicAttributes[$name]); |
|
177 return; |
|
178 } |
|
179 |
|
180 /** |
|
181 * __get() - Get a property via property call $metadata->foo |
|
182 * |
|
183 * @param string $name |
|
184 * @return mixed |
|
185 */ |
|
186 public function __get($name) |
|
187 { |
|
188 if (method_exists($this, 'get' . $name)) { |
|
189 return $this->{'get' . $name}(); |
|
190 } elseif (array_key_exists($name, $this->_dynamicAttributes)) { |
|
191 return $this->_dynamicAttributes[$name]; |
|
192 } else { |
|
193 require_once 'Zend/Tool/Framework/Registry/Exception.php'; |
|
194 throw new Zend_Tool_Framework_Registry_Exception('Property ' . $name . ' was not located in this metadata.'); |
|
195 } |
|
196 } |
|
197 |
|
198 /** |
|
199 * __set() - Set a property via the magic set $metadata->foo = 'foo' |
|
200 * |
|
201 * @param string $name |
|
202 * @param mixed $value |
|
203 */ |
|
204 public function __set($name, $value) |
|
205 { |
|
206 if (method_exists($this, 'set' . $name)) { |
|
207 $this->{'set' . $name}($value); |
|
208 return $this; |
|
209 } else { |
|
210 $this->_dynamicAttributes[$name] = $value; |
|
211 return $this; |
|
212 } |
|
213 // { |
|
214 // require_once 'Zend/Tool/Framework/Registry/Exception.php'; |
|
215 // throw new Zend_Tool_Framework_Registry_Exception('Property ' . $name . ' was not located in this registry.'); |
|
216 // } |
|
217 } |
|
218 |
|
219 } |