PageRenderTime 60ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://gitlab.com/devtoannh/cafe
PHP | 219 lines | 85 code | 21 blank | 113 comment | 5 complexity | c42dfee0b0625b5cffebcff8cd07955d MD5 | raw file
  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: Dynamic.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_Dynamic
  37. implements Zend_Tool_Framework_Metadata_Interface, Zend_Tool_Framework_Metadata_Attributable
  38. {
  39. /**
  40. * @var string
  41. */
  42. protected $_type = 'Dynamic';
  43. /**
  44. * @var string
  45. */
  46. protected $_name = null;
  47. /**
  48. * @var string
  49. */
  50. protected $_value = null;
  51. /**
  52. * @var array
  53. */
  54. protected $_dynamicAttributes = array();
  55. public function __construct($options = array())
  56. {
  57. if ($options) {
  58. $this->setOptions($options);
  59. }
  60. }
  61. public function setOptions(Array $options = array())
  62. {
  63. foreach ($options as $optName => $optValue) {
  64. $methodName = 'set' . $optName;
  65. $this->{$methodName}($optValue);
  66. }
  67. }
  68. /**
  69. * setType()
  70. *
  71. * @param string $type
  72. * @return Zend_Tool_Framework_Metadata_Dynamic
  73. */
  74. public function setType($type)
  75. {
  76. $this->_type = $type;
  77. return $this;
  78. }
  79. /**
  80. * getType()
  81. *
  82. * The type of metadata this describes
  83. *
  84. * @return string
  85. */
  86. public function getType()
  87. {
  88. return $this->_type;
  89. }
  90. /**
  91. * setName()
  92. *
  93. * @param string $name
  94. * @return Zend_Tool_Framework_Metadata_Dynamic
  95. */
  96. public function setName($name)
  97. {
  98. $this->_name = $name;
  99. return $this;
  100. }
  101. /**
  102. * getName()
  103. *
  104. * Metadata name
  105. *
  106. * @return string
  107. */
  108. public function getName()
  109. {
  110. return $this->_name;
  111. }
  112. /**
  113. * setValue()
  114. *
  115. * @param mixed $value
  116. * @return Zend_Tool_Framework_Metadata_Dynamic
  117. */
  118. public function setValue($value)
  119. {
  120. $this->_value = $value;
  121. return $this;
  122. }
  123. /**
  124. * getValue()
  125. *
  126. * Metadata Value
  127. *
  128. * @return string
  129. */
  130. public function getValue()
  131. {
  132. return $this->_value;
  133. }
  134. public function getAttributes()
  135. {
  136. return $this->_dynamicAttributes;
  137. }
  138. /**
  139. * __isset()
  140. *
  141. * Check if an attrbute is set
  142. *
  143. * @param string $name
  144. * @return bool
  145. */
  146. public function __isset($name)
  147. {
  148. return isset($this->_dynamicAttributes[$name]);
  149. }
  150. /**
  151. * __unset()
  152. *
  153. * @param string $name
  154. * @return null
  155. */
  156. public function __unset($name)
  157. {
  158. unset($this->_dynamicAttributes[$name]);
  159. return;
  160. }
  161. /**
  162. * __get() - Get a property via property call $metadata->foo
  163. *
  164. * @param string $name
  165. * @return mixed
  166. */
  167. public function __get($name)
  168. {
  169. if (method_exists($this, 'get' . $name)) {
  170. return $this->{'get' . $name}();
  171. } elseif (array_key_exists($name, $this->_dynamicAttributes)) {
  172. return $this->_dynamicAttributes[$name];
  173. } else {
  174. require_once 'Zend/Tool/Framework/Registry/Exception.php';
  175. throw new Zend_Tool_Framework_Registry_Exception('Property ' . $name . ' was not located in this metadata.');
  176. }
  177. }
  178. /**
  179. * __set() - Set a property via the magic set $metadata->foo = 'foo'
  180. *
  181. * @param string $name
  182. * @param mixed $value
  183. */
  184. public function __set($name, $value)
  185. {
  186. if (method_exists($this, 'set' . $name)) {
  187. $this->{'set' . $name}($value);
  188. return $this;
  189. } else {
  190. $this->_dynamicAttributes[$name] = $value;
  191. return $this;
  192. }
  193. // {
  194. // require_once 'Zend/Tool/Framework/Registry/Exception.php';
  195. // throw new Zend_Tool_Framework_Registry_Exception('Property ' . $name . ' was not located in this registry.');
  196. // }
  197. }
  198. }