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

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

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