web/lib/Zend/Server/Method/Parameter.php
changeset 64 162c1de6545a
parent 19 1c2f13fd785c
child 68 ecaf28ffe26e
equal deleted inserted replaced
63:5b37998e522e 64:162c1de6545a
       
     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_Server
       
    17  * @subpackage Method
       
    18  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    20  * @version    $Id: Parameter.php 20096 2010-01-06 02:05:09Z bkarwin $
       
    21  */
       
    22 
       
    23 /**
       
    24  * Method parameter metadata
       
    25  *
       
    26  * @category   Zend
       
    27  * @package    Zend_Server
       
    28  * @subpackage Method
       
    29  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    30  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    31  */
       
    32 class Zend_Server_Method_Parameter
       
    33 {
       
    34     /**
       
    35      * @var mixed Default parameter value
       
    36      */
       
    37     protected $_defaultValue;
       
    38 
       
    39     /**
       
    40      * @var string Parameter description
       
    41      */
       
    42     protected $_description = '';
       
    43 
       
    44     /**
       
    45      * @var string Parameter variable name
       
    46      */
       
    47     protected $_name;
       
    48 
       
    49     /**
       
    50      * @var bool Is parameter optional?
       
    51      */
       
    52     protected $_optional = false;
       
    53 
       
    54     /**
       
    55      * @var string Parameter type
       
    56      */
       
    57     protected $_type = 'mixed';
       
    58 
       
    59     /**
       
    60      * Constructor
       
    61      *
       
    62      * @param  null|array $options
       
    63      * @return void
       
    64      */
       
    65     public function __construct($options = null)
       
    66     {
       
    67         if (is_array($options)) {
       
    68             $this->setOptions($options);
       
    69         }
       
    70     }
       
    71 
       
    72     /**
       
    73      * Set object state from array of options
       
    74      *
       
    75      * @param  array $options
       
    76      * @return Zend_Server_Method_Parameter
       
    77      */
       
    78     public function setOptions(array $options)
       
    79     {
       
    80         foreach ($options as $key => $value) {
       
    81             $method = 'set' . ucfirst($key);
       
    82             if (method_exists($this, $method)) {
       
    83                 $this->$method($value);
       
    84             }
       
    85         }
       
    86         return $this;
       
    87     }
       
    88 
       
    89     /**
       
    90      * Set default value
       
    91      *
       
    92      * @param  mixed $defaultValue
       
    93      * @return Zend_Server_Method_Parameter
       
    94      */
       
    95     public function setDefaultValue($defaultValue)
       
    96     {
       
    97         $this->_defaultValue = $defaultValue;
       
    98         return $this;
       
    99     }
       
   100 
       
   101     /**
       
   102      * Retrieve default value
       
   103      *
       
   104      * @return mixed
       
   105      */
       
   106     public function getDefaultValue()
       
   107     {
       
   108         return $this->_defaultValue;
       
   109     }
       
   110 
       
   111     /**
       
   112      * Set description
       
   113      *
       
   114      * @param  string $description
       
   115      * @return Zend_Server_Method_Parameter
       
   116      */
       
   117     public function setDescription($description)
       
   118     {
       
   119         $this->_description = (string) $description;
       
   120         return $this;
       
   121     }
       
   122 
       
   123     /**
       
   124      * Retrieve description
       
   125      *
       
   126      * @return string
       
   127      */
       
   128     public function getDescription()
       
   129     {
       
   130         return $this->_description;
       
   131     }
       
   132 
       
   133     /**
       
   134      * Set name
       
   135      *
       
   136      * @param  string $name
       
   137      * @return Zend_Server_Method_Parameter
       
   138      */
       
   139     public function setName($name)
       
   140     {
       
   141         $this->_name = (string) $name;
       
   142         return $this;
       
   143     }
       
   144 
       
   145     /**
       
   146      * Retrieve name
       
   147      *
       
   148      * @return string
       
   149      */
       
   150     public function getName()
       
   151     {
       
   152         return $this->_name;
       
   153     }
       
   154 
       
   155     /**
       
   156      * Set optional flag
       
   157      *
       
   158      * @param  bool $flag
       
   159      * @return Zend_Server_Method_Parameter
       
   160      */
       
   161     public function setOptional($flag)
       
   162     {
       
   163         $this->_optional = (bool) $flag;
       
   164         return $this;
       
   165     }
       
   166 
       
   167     /**
       
   168      * Is the parameter optional?
       
   169      *
       
   170      * @return bool
       
   171      */
       
   172     public function isOptional()
       
   173     {
       
   174         return $this->_optional;
       
   175     }
       
   176 
       
   177     /**
       
   178      * Set parameter type
       
   179      *
       
   180      * @param  string $type
       
   181      * @return Zend_Server_Method_Parameter
       
   182      */
       
   183     public function setType($type)
       
   184     {
       
   185         $this->_type = (string) $type;
       
   186         return $this;
       
   187     }
       
   188 
       
   189     /**
       
   190      * Retrieve parameter type
       
   191      *
       
   192      * @return string
       
   193      */
       
   194     public function getType()
       
   195     {
       
   196         return $this->_type;
       
   197     }
       
   198 
       
   199     /**
       
   200      * Cast to array
       
   201      *
       
   202      * @return array
       
   203      */
       
   204     public function toArray()
       
   205     {
       
   206         return array(
       
   207             'type'         => $this->getType(),
       
   208             'name'         => $this->getName(),
       
   209             'optional'     => $this->isOptional(),
       
   210             'defaultValue' => $this->getDefaultValue(),
       
   211             'description'  => $this->getDescription(),
       
   212         );
       
   213     }
       
   214 }