Basic.php 5.1 KB

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