PageRenderTime 36ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/zendframework/zend-server/src/Method/Parameter.php

https://gitlab.com/yousafsyed/easternglamor
PHP | 206 lines | 81 code | 19 blank | 106 comment | 2 complexity | e08afc3540c96135e54b0b199eadf899 MD5 | raw file
  1. <?php
  2. /**
  3. * Zend Framework (http://framework.zend.com/)
  4. *
  5. * @link http://github.com/zendframework/zf2 for the canonical source repository
  6. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  7. * @license http://framework.zend.com/license/new-bsd New BSD License
  8. */
  9. namespace Zend\Server\Method;
  10. /**
  11. * Method parameter metadata
  12. */
  13. class Parameter
  14. {
  15. /**
  16. * Default parameter value
  17. *
  18. * @var mixed
  19. */
  20. protected $defaultValue;
  21. /**
  22. * Parameter description
  23. *
  24. * @var string
  25. */
  26. protected $description = '';
  27. /**
  28. * Parameter variable name
  29. *
  30. * @var string
  31. */
  32. protected $name;
  33. /**
  34. * Is parameter optional?
  35. *
  36. * @var bool
  37. */
  38. protected $optional = false;
  39. /**
  40. * Parameter type
  41. *
  42. * @var string
  43. */
  44. protected $type = 'mixed';
  45. /**
  46. * Constructor
  47. *
  48. * @param null|array $options
  49. */
  50. public function __construct($options = null)
  51. {
  52. if (is_array($options)) {
  53. $this->setOptions($options);
  54. }
  55. }
  56. /**
  57. * Set object state from array of options
  58. *
  59. * @param array $options
  60. * @return \Zend\Server\Method\Parameter
  61. */
  62. public function setOptions(array $options)
  63. {
  64. foreach ($options as $key => $value) {
  65. $method = 'set' . ucfirst($key);
  66. if (method_exists($this, $method)) {
  67. $this->$method($value);
  68. }
  69. }
  70. return $this;
  71. }
  72. /**
  73. * Set default value
  74. *
  75. * @param mixed $defaultValue
  76. * @return \Zend\Server\Method\Parameter
  77. */
  78. public function setDefaultValue($defaultValue)
  79. {
  80. $this->defaultValue = $defaultValue;
  81. return $this;
  82. }
  83. /**
  84. * Retrieve default value
  85. *
  86. * @return mixed
  87. */
  88. public function getDefaultValue()
  89. {
  90. return $this->defaultValue;
  91. }
  92. /**
  93. * Set description
  94. *
  95. * @param string $description
  96. * @return \Zend\Server\Method\Parameter
  97. */
  98. public function setDescription($description)
  99. {
  100. $this->description = (string) $description;
  101. return $this;
  102. }
  103. /**
  104. * Retrieve description
  105. *
  106. * @return string
  107. */
  108. public function getDescription()
  109. {
  110. return $this->description;
  111. }
  112. /**
  113. * Set name
  114. *
  115. * @param string $name
  116. * @return \Zend\Server\Method\Parameter
  117. */
  118. public function setName($name)
  119. {
  120. $this->name = (string) $name;
  121. return $this;
  122. }
  123. /**
  124. * Retrieve name
  125. *
  126. * @return string
  127. */
  128. public function getName()
  129. {
  130. return $this->name;
  131. }
  132. /**
  133. * Set optional flag
  134. *
  135. * @param bool $flag
  136. * @return \Zend\Server\Method\Parameter
  137. */
  138. public function setOptional($flag)
  139. {
  140. $this->optional = (bool) $flag;
  141. return $this;
  142. }
  143. /**
  144. * Is the parameter optional?
  145. *
  146. * @return bool
  147. */
  148. public function isOptional()
  149. {
  150. return $this->optional;
  151. }
  152. /**
  153. * Set parameter type
  154. *
  155. * @param string $type
  156. * @return \Zend\Server\Method\Parameter
  157. */
  158. public function setType($type)
  159. {
  160. $this->type = (string) $type;
  161. return $this;
  162. }
  163. /**
  164. * Retrieve parameter type
  165. *
  166. * @return string
  167. */
  168. public function getType()
  169. {
  170. return $this->type;
  171. }
  172. /**
  173. * Cast to array
  174. *
  175. * @return array
  176. */
  177. public function toArray()
  178. {
  179. return array(
  180. 'type' => $this->getType(),
  181. 'name' => $this->getName(),
  182. 'optional' => $this->isOptional(),
  183. 'defaultValue' => $this->getDefaultValue(),
  184. 'description' => $this->getDescription(),
  185. );
  186. }
  187. }