PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/zendframework/zendframework/library/Zend/Server/Reflection/ReflectionParameter.php

https://bitbucket.org/pcelta/zf2
PHP | 150 lines | 52 code | 16 blank | 82 comment | 5 complexity | 7e31ab860b909fe436f208a97351a084 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-2012 Zend Technologies USA Inc. (http://www.zend.com)
  7. * @license http://framework.zend.com/license/new-bsd New BSD License
  8. * @package Zend_Server
  9. */
  10. namespace Zend\Server\Reflection;
  11. /**
  12. * Parameter Reflection
  13. *
  14. * Decorates a ReflectionParameter to allow setting the parameter type
  15. *
  16. * @category Zend
  17. * @package Zend_Server
  18. * @subpackage Zend_Server_Reflection
  19. */
  20. class ReflectionParameter
  21. {
  22. /**
  23. * @var ReflectionParameter
  24. */
  25. protected $reflection;
  26. /**
  27. * Parameter position
  28. * @var int
  29. */
  30. protected $position;
  31. /**
  32. * Parameter type
  33. * @var string
  34. */
  35. protected $type;
  36. /**
  37. * Parameter description
  38. * @var string
  39. */
  40. protected $description;
  41. /**
  42. * Constructor
  43. *
  44. * @param \ReflectionParameter $r
  45. * @param string $type Parameter type
  46. * @param string $description Parameter description
  47. */
  48. public function __construct(\ReflectionParameter $r, $type = 'mixed', $description = '')
  49. {
  50. $this->reflection = $r;
  51. $this->setType($type);
  52. $this->setDescription($description);
  53. }
  54. /**
  55. * Proxy reflection calls
  56. *
  57. * @param string $method
  58. * @param array $args
  59. * @throws Exception\BadMethodCallException
  60. * @return mixed
  61. */
  62. public function __call($method, $args)
  63. {
  64. if (method_exists($this->reflection, $method)) {
  65. return call_user_func_array(array($this->reflection, $method), $args);
  66. }
  67. throw new Exception\BadMethodCallException('Invalid reflection method');
  68. }
  69. /**
  70. * Retrieve parameter type
  71. *
  72. * @return string
  73. */
  74. public function getType()
  75. {
  76. return $this->type;
  77. }
  78. /**
  79. * Set parameter type
  80. *
  81. * @param string|null $type
  82. * @throws Exception\InvalidArgumentException
  83. * @return void
  84. */
  85. public function setType($type)
  86. {
  87. if (!is_string($type) && (null !== $type)) {
  88. throw new Exception\InvalidArgumentException('Invalid parameter type');
  89. }
  90. $this->type = $type;
  91. }
  92. /**
  93. * Retrieve parameter description
  94. *
  95. * @return string
  96. */
  97. public function getDescription()
  98. {
  99. return $this->description;
  100. }
  101. /**
  102. * Set parameter description
  103. *
  104. * @param string|null $description
  105. * @throws Exception\InvalidArgumentException
  106. * @return void
  107. */
  108. public function setDescription($description)
  109. {
  110. if (!is_string($description) && (null !== $description)) {
  111. throw new Exception\InvalidArgumentException('Invalid parameter description');
  112. }
  113. $this->description = $description;
  114. }
  115. /**
  116. * Set parameter position
  117. *
  118. * @param int $index
  119. * @return void
  120. */
  121. public function setPosition($index)
  122. {
  123. $this->position = (int) $index;
  124. }
  125. /**
  126. * Return parameter position
  127. *
  128. * @return int
  129. */
  130. public function getPosition()
  131. {
  132. return $this->position;
  133. }
  134. }