Dynamic.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 array
  40. */
  41. protected $_dynamicAttributes = array();
  42. /**
  43. * __isset()
  44. *
  45. * Check if an attrbute is set
  46. *
  47. * @param string $name
  48. * @return bool
  49. */
  50. public function __isset($name)
  51. {
  52. return isset($this->_dynamicAttributes[$name]);
  53. }
  54. /**
  55. * __unset()
  56. *
  57. * @param string $name
  58. * @return null
  59. */
  60. public function __unset($name)
  61. {
  62. unset($this->_dynamicAttributes[$name]);
  63. return;
  64. }
  65. /**
  66. * __get() - Get a property via property call $metadata->foo
  67. *
  68. * @param string $name
  69. * @return mixed
  70. */
  71. public function __get($name)
  72. {
  73. if (method_exists($this, 'get' . $name)) {
  74. return $this->{'get' . $name}();
  75. } elseif (array_key_exists($name, $this->_dynamicAttributes)) {
  76. return ;
  77. } else {
  78. require_once 'Zend/Tool/Framework/Registry/Exception.php';
  79. throw new Zend_Tool_Framework_Registry_Exception('Property ' . $name . ' was not located in this metadata.');
  80. }
  81. }
  82. /**
  83. * __set() - Set a property via the magic set $metadata->foo = 'foo'
  84. *
  85. * @param string $name
  86. * @param mixed $value
  87. */
  88. public function __set($name, $value)
  89. {
  90. if (method_exists($this, 'set' . $name)) {
  91. $this->{'set' . $name}($value);
  92. return;
  93. } else {
  94. require_once 'Zend/Tool/Framework/Registry/Exception.php';
  95. throw new Zend_Tool_Framework_Registry_Exception('Property ' . $name . ' was not located in this registry.');
  96. }
  97. }
  98. }