Dynamic.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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_Dynamic implements Zend_Tool_Framework_Metadata_Interface
  33. {
  34. /**
  35. * @var string
  36. */
  37. protected $_type = 'Dynamic';
  38. /**
  39. * @var string
  40. */
  41. protected $_name = null;
  42. /**
  43. * @var string
  44. */
  45. protected $_value = null;
  46. /**
  47. * @var array
  48. */
  49. protected $_dynamicAttributes = array();
  50. /**
  51. * getType()
  52. *
  53. * The type of metadata this describes
  54. *
  55. * @return string
  56. */
  57. public function getType()
  58. {
  59. return $this->_type;
  60. }
  61. /**
  62. * getName()
  63. *
  64. * Metadata name
  65. *
  66. * @return string
  67. */
  68. public function getName()
  69. {
  70. return $this->_name;
  71. }
  72. /**
  73. * getValue()
  74. *
  75. * Metadata Value
  76. *
  77. * @return string
  78. */
  79. public function getValue()
  80. {
  81. return $this->_value;
  82. }
  83. /**
  84. * __isset()
  85. *
  86. * Check if an attrbute is set
  87. *
  88. * @param string $name
  89. * @return bool
  90. */
  91. public function __isset($name)
  92. {
  93. return isset($this->_dynamicAttributes[$name]);
  94. }
  95. /**
  96. * __unset()
  97. *
  98. * @param string $name
  99. * @return null
  100. */
  101. public function __unset($name)
  102. {
  103. unset($this->_dynamicAttributes[$name]);
  104. return;
  105. }
  106. /**
  107. * __get() - Get a property via property call $metadata->foo
  108. *
  109. * @param string $name
  110. * @return mixed
  111. */
  112. public function __get($name)
  113. {
  114. if (method_exists($this, 'get' . $name)) {
  115. return $this->{'get' . $name}();
  116. } elseif (array_key_exists($name, $this->_dynamicAttributes)) {
  117. return ;
  118. } else {
  119. require_once 'Zend/Tool/Framework/Registry/Exception.php';
  120. throw new Zend_Tool_Framework_Registry_Exception('Property ' . $name . ' was not located in this metadata.');
  121. }
  122. }
  123. /**
  124. * __set() - Set a property via the magic set $metadata->foo = 'foo'
  125. *
  126. * @param string $name
  127. * @param mixed $value
  128. */
  129. public function __set($name, $value)
  130. {
  131. if (method_exists($this, 'set' . $name)) {
  132. $this->{'set' . $name}($value);
  133. return;
  134. } else {
  135. require_once 'Zend/Tool/Framework/Registry/Exception.php';
  136. throw new Zend_Tool_Framework_Registry_Exception('Property ' . $name . ' was not located in this registry.');
  137. }
  138. }
  139. }