|
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: Basic.php 22662 2010-07-24 17:37:36Z mabe $ |
|
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_Basic |
|
40 implements Zend_Tool_Framework_Metadata_Interface, Zend_Tool_Framework_Metadata_Attributable |
|
41 { |
|
42 |
|
43 /**#@+ |
|
44 * Search constants |
|
45 */ |
|
46 const ATTRIBUTES_ALL = 'attributesAll'; |
|
47 const ATTRIBUTES_NO_PARENT = 'attributesParent'; |
|
48 /**#@-*/ |
|
49 |
|
50 /**#@+ |
|
51 * @var string |
|
52 */ |
|
53 protected $_type = 'Basic'; |
|
54 protected $_name = null; |
|
55 protected $_value = null; |
|
56 /**#@-*/ |
|
57 |
|
58 /** |
|
59 * @var mixed |
|
60 */ |
|
61 protected $_reference = null; |
|
62 |
|
63 /** |
|
64 * Constructor - allows for the setting of options |
|
65 * |
|
66 * @param array $options |
|
67 */ |
|
68 public function __construct(Array $options = array()) |
|
69 { |
|
70 if ($options) { |
|
71 $this->setOptions($options); |
|
72 } |
|
73 } |
|
74 |
|
75 /** |
|
76 * setOptions() - standard issue implementation, this will set any |
|
77 * options that are supported via a set method. |
|
78 * |
|
79 * @param array $options |
|
80 * @return Zend_Tool_Framework_Metadata_Basic |
|
81 */ |
|
82 public function setOptions(Array $options) |
|
83 { |
|
84 foreach ($options as $optionName => $optionValue) { |
|
85 $setMethod = 'set' . $optionName; |
|
86 if (method_exists($this, $setMethod)) { |
|
87 $this->{$setMethod}($optionValue); |
|
88 } |
|
89 } |
|
90 |
|
91 return $this; |
|
92 } |
|
93 |
|
94 /** |
|
95 * getType() |
|
96 * |
|
97 * @return string |
|
98 */ |
|
99 public function getType() |
|
100 { |
|
101 return $this->_type; |
|
102 } |
|
103 |
|
104 /** |
|
105 * setType() |
|
106 * |
|
107 * @param string $type |
|
108 * @return Zend_Tool_Framework_Metadata_Basic |
|
109 */ |
|
110 public function setType($type) |
|
111 { |
|
112 $this->_type = $type; |
|
113 return $this; |
|
114 } |
|
115 |
|
116 /** |
|
117 * getName() |
|
118 * |
|
119 * @return string |
|
120 */ |
|
121 public function getName() |
|
122 { |
|
123 return $this->_name; |
|
124 } |
|
125 |
|
126 /** |
|
127 * setName() |
|
128 * |
|
129 * @param string $name |
|
130 * @return Zend_Tool_Framework_Metadata_Basic |
|
131 */ |
|
132 public function setName($name) |
|
133 { |
|
134 $this->_name = $name; |
|
135 return $this; |
|
136 } |
|
137 |
|
138 /** |
|
139 * getValue() |
|
140 * |
|
141 * @return mixed |
|
142 */ |
|
143 public function getValue() |
|
144 { |
|
145 return $this->_value; |
|
146 } |
|
147 |
|
148 /** |
|
149 * setValue() |
|
150 * |
|
151 * @param unknown_type $Value |
|
152 * @return Zend_Tool_Framework_Metadata_Basic |
|
153 */ |
|
154 public function setValue($value) |
|
155 { |
|
156 $this->_value = $value; |
|
157 return $this; |
|
158 } |
|
159 |
|
160 /** |
|
161 * setReference() |
|
162 * |
|
163 * @param mixed $reference |
|
164 * @return Zend_Tool_Framework_Metadata_Basic |
|
165 */ |
|
166 public function setReference($reference) |
|
167 { |
|
168 $this->_reference = $reference; |
|
169 return $this; |
|
170 } |
|
171 |
|
172 /** |
|
173 * getReference() |
|
174 * |
|
175 * @return mixed |
|
176 */ |
|
177 public function getReference() |
|
178 { |
|
179 return $this->_reference; |
|
180 } |
|
181 |
|
182 /** |
|
183 * getAttributes() - this will retrieve any attributes of this object that exist as properties |
|
184 * This is most useful for printing metadata. |
|
185 * |
|
186 * @param const $type |
|
187 * @return array |
|
188 */ |
|
189 public function getAttributes($type = self::ATTRIBUTES_ALL, $stringRepresentationOfNonScalars = false) |
|
190 { |
|
191 $thisReflection = new ReflectionObject($this); |
|
192 |
|
193 $metadataPairValues = array(); |
|
194 |
|
195 foreach (get_object_vars($this) as $varName => $varValue) { |
|
196 if ($type == self::ATTRIBUTES_NO_PARENT && ($thisReflection->getProperty($varName)->getDeclaringClass()->getName() == 'Zend_Tool_Framework_Metadata_Basic')) { |
|
197 continue; |
|
198 } |
|
199 |
|
200 if ($stringRepresentationOfNonScalars) { |
|
201 |
|
202 if (is_object($varValue)) { |
|
203 $varValue = '(object)'; |
|
204 } |
|
205 |
|
206 if ($varValue === null) { |
|
207 $varValue = '(null)'; |
|
208 } |
|
209 |
|
210 } |
|
211 |
|
212 $metadataPairValues[ltrim($varName, '_')] = $varValue; |
|
213 } |
|
214 |
|
215 return $metadataPairValues; |
|
216 } |
|
217 |
|
218 /** |
|
219 * __toString() - string representation of this object |
|
220 * |
|
221 * @return string |
|
222 */ |
|
223 public function __toString() |
|
224 { |
|
225 return 'Type: ' . $this->_type . ', Name: ' . $this->_name . ', Value: ' . (is_array($this->_value) ? http_build_query($this->_value) : (string) $this->_value); |
|
226 } |
|
227 } |