File indexing completed on 2025-01-19 05:21:36
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Tool 0017 * @subpackage Framework 0018 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0019 * @license http://framework.zend.com/license/new-bsd New BSD License 0020 * @version $Id$ 0021 */ 0022 0023 /** 0024 * @see Zend_Tool_Framework_Metadata_Interface 0025 */ 0026 // require_once 'Zend/Tool/Framework/Metadata/Interface.php'; 0027 0028 /** 0029 * @see Zend_Tool_Framework_Metadata_Attributable 0030 */ 0031 // require_once 'Zend/Tool/Framework/Metadata/Attributable.php'; 0032 0033 /** 0034 * @category Zend 0035 * @package Zend_Tool 0036 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0037 * @license http://framework.zend.com/license/new-bsd New BSD License 0038 */ 0039 class Zend_Tool_Framework_Metadata_Dynamic 0040 implements Zend_Tool_Framework_Metadata_Interface, Zend_Tool_Framework_Metadata_Attributable 0041 { 0042 0043 /** 0044 * @var string 0045 */ 0046 protected $_type = 'Dynamic'; 0047 0048 /** 0049 * @var string 0050 */ 0051 protected $_name = null; 0052 0053 /** 0054 * @var string 0055 */ 0056 protected $_value = null; 0057 0058 /** 0059 * @var array 0060 */ 0061 protected $_dynamicAttributes = array(); 0062 0063 public function __construct($options = array()) 0064 { 0065 if ($options) { 0066 $this->setOptions($options); 0067 } 0068 } 0069 0070 public function setOptions(Array $options = array()) 0071 { 0072 foreach ($options as $optName => $optValue) { 0073 $methodName = 'set' . $optName; 0074 $this->{$methodName}($optValue); 0075 } 0076 } 0077 0078 /** 0079 * setType() 0080 * 0081 * @param string $type 0082 * @return Zend_Tool_Framework_Metadata_Dynamic 0083 */ 0084 public function setType($type) 0085 { 0086 $this->_type = $type; 0087 return $this; 0088 } 0089 0090 /** 0091 * getType() 0092 * 0093 * The type of metadata this describes 0094 * 0095 * @return string 0096 */ 0097 public function getType() 0098 { 0099 return $this->_type; 0100 } 0101 0102 /** 0103 * setName() 0104 * 0105 * @param string $name 0106 * @return Zend_Tool_Framework_Metadata_Dynamic 0107 */ 0108 public function setName($name) 0109 { 0110 $this->_name = $name; 0111 return $this; 0112 } 0113 0114 /** 0115 * getName() 0116 * 0117 * Metadata name 0118 * 0119 * @return string 0120 */ 0121 public function getName() 0122 { 0123 return $this->_name; 0124 } 0125 0126 /** 0127 * setValue() 0128 * 0129 * @param mixed $value 0130 * @return Zend_Tool_Framework_Metadata_Dynamic 0131 */ 0132 public function setValue($value) 0133 { 0134 $this->_value = $value; 0135 return $this; 0136 } 0137 0138 /** 0139 * getValue() 0140 * 0141 * Metadata Value 0142 * 0143 * @return string 0144 */ 0145 public function getValue() 0146 { 0147 return $this->_value; 0148 } 0149 0150 public function getAttributes() 0151 { 0152 return $this->_dynamicAttributes; 0153 } 0154 0155 /** 0156 * __isset() 0157 * 0158 * Check if an attrbute is set 0159 * 0160 * @param string $name 0161 * @return bool 0162 */ 0163 public function __isset($name) 0164 { 0165 return isset($this->_dynamicAttributes[$name]); 0166 } 0167 0168 /** 0169 * __unset() 0170 * 0171 * @param string $name 0172 * @return null 0173 */ 0174 public function __unset($name) 0175 { 0176 unset($this->_dynamicAttributes[$name]); 0177 return; 0178 } 0179 0180 /** 0181 * __get() - Get a property via property call $metadata->foo 0182 * 0183 * @param string $name 0184 * @return mixed 0185 */ 0186 public function __get($name) 0187 { 0188 if (method_exists($this, 'get' . $name)) { 0189 return $this->{'get' . $name}(); 0190 } elseif (array_key_exists($name, $this->_dynamicAttributes)) { 0191 return $this->_dynamicAttributes[$name]; 0192 } else { 0193 // require_once 'Zend/Tool/Framework/Registry/Exception.php'; 0194 throw new Zend_Tool_Framework_Registry_Exception('Property ' . $name . ' was not located in this metadata.'); 0195 } 0196 } 0197 0198 /** 0199 * __set() - Set a property via the magic set $metadata->foo = 'foo' 0200 * 0201 * @param string $name 0202 * @param mixed $value 0203 */ 0204 public function __set($name, $value) 0205 { 0206 if (method_exists($this, 'set' . $name)) { 0207 $this->{'set' . $name}($value); 0208 return $this; 0209 } else { 0210 $this->_dynamicAttributes[$name] = $value; 0211 return $this; 0212 } 0213 // { 0214 // // require_once 'Zend/Tool/Framework/Registry/Exception.php'; 0215 // throw new Zend_Tool_Framework_Registry_Exception('Property ' . $name . ' was not located in this registry.'); 0216 // } 0217 } 0218 0219 }