PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/library/Zend/Server/Method/Parameter.php

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