PageRenderTime 36ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/library/Zend/Tool/Framework/Metadata/Basic.php

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