File indexing completed on 2024-12-29 05:28:08

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_Basic
0040     implements Zend_Tool_Framework_Metadata_Interface, Zend_Tool_Framework_Metadata_Attributable
0041 {
0042 
0043     /**#@+
0044      * Search constants
0045      */
0046     const ATTRIBUTES_ALL        = 'attributesAll';
0047     const ATTRIBUTES_NO_PARENT  = 'attributesParent';
0048     /**#@-*/
0049 
0050     /**#@+
0051      * @var string
0052      */
0053     protected $_type        = 'Basic';
0054     protected $_name        = null;
0055     protected $_value       = null;
0056     /**#@-*/
0057 
0058     /**
0059      * @var mixed
0060      */
0061     protected $_reference   = null;
0062 
0063     /**
0064      * Constructor - allows for the setting of options
0065      *
0066      * @param array $options
0067      */
0068     public function __construct(Array $options = array())
0069     {
0070         if ($options) {
0071             $this->setOptions($options);
0072         }
0073     }
0074 
0075     /**
0076      * setOptions() - standard issue implementation, this will set any
0077      * options that are supported via a set method.
0078      *
0079      * @param array $options
0080      * @return Zend_Tool_Framework_Metadata_Basic
0081      */
0082     public function setOptions(Array $options)
0083     {
0084         foreach ($options as $optionName => $optionValue) {
0085             $setMethod = 'set' . $optionName;
0086             if (method_exists($this, $setMethod)) {
0087                 $this->{$setMethod}($optionValue);
0088             }
0089         }
0090 
0091         return $this;
0092     }
0093 
0094     /**
0095      * getType()
0096      *
0097      * @return string
0098      */
0099     public function getType()
0100     {
0101         return $this->_type;
0102     }
0103 
0104     /**
0105      * setType()
0106      *
0107      * @param string $type
0108      * @return Zend_Tool_Framework_Metadata_Basic
0109      */
0110     public function setType($type)
0111     {
0112         $this->_type = $type;
0113         return $this;
0114     }
0115 
0116     /**
0117      * getName()
0118      *
0119      * @return string
0120      */
0121     public function getName()
0122     {
0123         return $this->_name;
0124     }
0125 
0126     /**
0127      * setName()
0128      *
0129      * @param string $name
0130      * @return Zend_Tool_Framework_Metadata_Basic
0131      */
0132     public function setName($name)
0133     {
0134         $this->_name = $name;
0135         return $this;
0136     }
0137 
0138     /**
0139      * getValue()
0140      *
0141      * @return mixed
0142      */
0143     public function getValue()
0144     {
0145         return $this->_value;
0146     }
0147 
0148     /**
0149      * setValue()
0150      *
0151      * @param unknown_type $Value
0152      * @return Zend_Tool_Framework_Metadata_Basic
0153      */
0154     public function setValue($value)
0155     {
0156         $this->_value = $value;
0157         return $this;
0158     }
0159 
0160     /**
0161      * setReference()
0162      *
0163      * @param mixed $reference
0164      * @return Zend_Tool_Framework_Metadata_Basic
0165      */
0166     public function setReference($reference)
0167     {
0168         $this->_reference = $reference;
0169         return $this;
0170     }
0171 
0172     /**
0173      * getReference()
0174      *
0175      * @return mixed
0176      */
0177     public function getReference()
0178     {
0179         return $this->_reference;
0180     }
0181 
0182     /**
0183      * getAttributes() - this will retrieve any attributes of this object that exist as properties
0184      * This is most useful for printing metadata.
0185      *
0186      * @param const $type
0187      * @return array
0188      */
0189     public function getAttributes($type = self::ATTRIBUTES_ALL, $stringRepresentationOfNonScalars = false)
0190     {
0191         $thisReflection = new ReflectionObject($this);
0192 
0193         $metadataPairValues = array();
0194 
0195         foreach (get_object_vars($this) as $varName => $varValue) {
0196             if ($type == self::ATTRIBUTES_NO_PARENT && ($thisReflection->getProperty($varName)->getDeclaringClass()->getName() == 'Zend_Tool_Framework_Metadata_Basic')) {
0197                 continue;
0198             }
0199 
0200             if ($stringRepresentationOfNonScalars) {
0201 
0202                 if (is_object($varValue)) {
0203                     $varValue = '(object)';
0204                 }
0205 
0206                 if ($varValue === null) {
0207                     $varValue = '(null)';
0208                 }
0209 
0210             }
0211 
0212             $metadataPairValues[ltrim($varName, '_')] = $varValue;
0213         }
0214 
0215         return $metadataPairValues;
0216     }
0217 
0218     /**
0219      * __toString() - string representation of this object
0220      *
0221      * @return string
0222      */
0223     public function __toString()
0224     {
0225         return 'Type: ' . $this->_type . ', Name: ' . $this->_name . ', Value: ' . (is_array($this->_value) ? http_build_query($this->_value) : (string) $this->_value);
0226     }
0227 }