2
0

Parameter.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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_Reflection
  17. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id$
  20. */
  21. /**
  22. * @category Zend
  23. * @package Zend_Reflection
  24. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  25. * @license http://framework.zend.com/license/new-bsd New BSD License
  26. */
  27. class Zend_Reflection_Parameter extends ReflectionParameter
  28. {
  29. /**
  30. * @var bool
  31. */
  32. protected $_isFromMethod = false;
  33. /**
  34. * Get declaring class reflection object
  35. *
  36. * @param string $reflectionClass Reflection class to use
  37. * @return Zend_Reflection_Class
  38. */
  39. public function getDeclaringClass($reflectionClass = 'Zend_Reflection_Class')
  40. {
  41. $phpReflection = parent::getDeclaringClass();
  42. $zendReflection = new $reflectionClass($phpReflection->getName());
  43. if (!$zendReflection instanceof Zend_Reflection_Class) {
  44. require_once 'Zend/Reflection/Exception.php';
  45. throw new Zend_Reflection_Exception('Invalid reflection class provided; must extend Zend_Reflection_Class');
  46. }
  47. unset($phpReflection);
  48. return $zendReflection;
  49. }
  50. /**
  51. * Get class reflection object
  52. *
  53. * @param string $reflectionClass Reflection class to use
  54. * @return Zend_Reflection_Class
  55. */
  56. public function getClass($reflectionClass = 'Zend_Reflection_Class')
  57. {
  58. $phpReflection = parent::getClass();
  59. $zendReflection = new $reflectionClass($phpReflection->getName());
  60. if (!$zendReflection instanceof Zend_Reflection_Class) {
  61. require_once 'Zend/Reflection/Exception.php';
  62. throw new Zend_Reflection_Exception('Invalid reflection class provided; must extend Zend_Reflection_Class');
  63. }
  64. unset($phpReflection);
  65. return $zendReflection;
  66. }
  67. /**
  68. * Get declaring function reflection object
  69. *
  70. * @param string $reflectionClass Reflection class to use
  71. * @return Zend_Reflection_Function|Zend_Reflection_Method
  72. */
  73. public function getDeclaringFunction($reflectionClass = null)
  74. {
  75. $phpReflection = parent::getDeclaringFunction();
  76. if ($phpReflection instanceof ReflectionMethod) {
  77. $baseClass = 'Zend_Reflection_Method';
  78. if (null === $reflectionClass) {
  79. $reflectionClass = $baseClass;
  80. }
  81. $zendReflection = new $reflectionClass($this->getDeclaringClass()->getName(), $phpReflection->getName());
  82. } else {
  83. $baseClass = 'Zend_Reflection_Function';
  84. if (null === $reflectionClass) {
  85. $reflectionClass = $baseClass;
  86. }
  87. $zendReflection = new $reflectionClass($phpReflection->getName());
  88. }
  89. if (!$zendReflection instanceof $baseClass) {
  90. require_once 'Zend/Reflection/Exception.php';
  91. throw new Zend_Reflection_Exception('Invalid reflection class provided; must extend ' . $baseClass);
  92. }
  93. unset($phpReflection);
  94. return $zendReflection;
  95. }
  96. /**
  97. * Get parameter type
  98. *
  99. * @return string
  100. */
  101. public function getType()
  102. {
  103. if ($docblock = $this->getDeclaringFunction()->getDocblock()) {
  104. $params = $docblock->getTags('param');
  105. if (isset($params[$this->getPosition() - 1])) {
  106. return $params[$this->getPosition() - 1]->getType();
  107. }
  108. }
  109. return null;
  110. }
  111. }