File indexing completed on 2025-01-19 05:21:27

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_Server
0017  * @subpackage Method
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  * Method parameter metadata
0025  *
0026  * @category   Zend
0027  * @package    Zend_Server
0028  * @subpackage Method
0029  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0030  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0031  */
0032 class Zend_Server_Method_Parameter
0033 {
0034     /**
0035      * @var mixed Default parameter value
0036      */
0037     protected $_defaultValue;
0038 
0039     /**
0040      * @var string Parameter description
0041      */
0042     protected $_description = '';
0043 
0044     /**
0045      * @var string Parameter variable name
0046      */
0047     protected $_name;
0048 
0049     /**
0050      * @var bool Is parameter optional?
0051      */
0052     protected $_optional = false;
0053 
0054     /**
0055      * @var string Parameter type
0056      */
0057     protected $_type = 'mixed';
0058 
0059     /**
0060      * Constructor
0061      *
0062      * @param  null|array $options
0063      * @return void
0064      */
0065     public function __construct($options = null)
0066     {
0067         if (is_array($options)) {
0068             $this->setOptions($options);
0069         }
0070     }
0071 
0072     /**
0073      * Set object state from array of options
0074      *
0075      * @param  array $options
0076      * @return Zend_Server_Method_Parameter
0077      */
0078     public function setOptions(array $options)
0079     {
0080         foreach ($options as $key => $value) {
0081             $method = 'set' . ucfirst($key);
0082             if (method_exists($this, $method)) {
0083                 $this->$method($value);
0084             }
0085         }
0086         return $this;
0087     }
0088 
0089     /**
0090      * Set default value
0091      *
0092      * @param  mixed $defaultValue
0093      * @return Zend_Server_Method_Parameter
0094      */
0095     public function setDefaultValue($defaultValue)
0096     {
0097         $this->_defaultValue = $defaultValue;
0098         return $this;
0099     }
0100 
0101     /**
0102      * Retrieve default value
0103      *
0104      * @return mixed
0105      */
0106     public function getDefaultValue()
0107     {
0108         return $this->_defaultValue;
0109     }
0110 
0111     /**
0112      * Set description
0113      *
0114      * @param  string $description
0115      * @return Zend_Server_Method_Parameter
0116      */
0117     public function setDescription($description)
0118     {
0119         $this->_description = (string) $description;
0120         return $this;
0121     }
0122 
0123     /**
0124      * Retrieve description
0125      *
0126      * @return string
0127      */
0128     public function getDescription()
0129     {
0130         return $this->_description;
0131     }
0132 
0133     /**
0134      * Set name
0135      *
0136      * @param  string $name
0137      * @return Zend_Server_Method_Parameter
0138      */
0139     public function setName($name)
0140     {
0141         $this->_name = (string) $name;
0142         return $this;
0143     }
0144 
0145     /**
0146      * Retrieve name
0147      *
0148      * @return string
0149      */
0150     public function getName()
0151     {
0152         return $this->_name;
0153     }
0154 
0155     /**
0156      * Set optional flag
0157      *
0158      * @param  bool $flag
0159      * @return Zend_Server_Method_Parameter
0160      */
0161     public function setOptional($flag)
0162     {
0163         $this->_optional = (bool) $flag;
0164         return $this;
0165     }
0166 
0167     /**
0168      * Is the parameter optional?
0169      *
0170      * @return bool
0171      */
0172     public function isOptional()
0173     {
0174         return $this->_optional;
0175     }
0176 
0177     /**
0178      * Set parameter type
0179      *
0180      * @param  string $type
0181      * @return Zend_Server_Method_Parameter
0182      */
0183     public function setType($type)
0184     {
0185         $this->_type = (string) $type;
0186         return $this;
0187     }
0188 
0189     /**
0190      * Retrieve parameter type
0191      *
0192      * @return string
0193      */
0194     public function getType()
0195     {
0196         return $this->_type;
0197     }
0198 
0199     /**
0200      * Cast to array
0201      *
0202      * @return array
0203      */
0204     public function toArray()
0205     {
0206         return array(
0207             'type'         => $this->getType(),
0208             'name'         => $this->getName(),
0209             'optional'     => $this->isOptional(),
0210             'defaultValue' => $this->getDefaultValue(),
0211             'description'  => $this->getDescription(),
0212         );
0213     }
0214 }