/framework/vendor/zend/Zend/Reflection/Function.php

http://zoop.googlecode.com/ · PHP · 129 lines · 65 code · 7 blank · 57 comment · 10 complexity · 3b005dfc2ca8bfe136c19808e3ab21c7 MD5 · raw file

  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-2010 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id: Function.php 20096 2010-01-06 02:05:09Z bkarwin $
  20. */
  21. /**
  22. * @see Zend_Reflection_Parameter
  23. */
  24. require_once 'Zend/Reflection/Parameter.php';
  25. /**
  26. * @category Zend
  27. * @package Zend_Reflection
  28. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  29. * @license http://framework.zend.com/license/new-bsd New BSD License
  30. */
  31. class Zend_Reflection_Function extends ReflectionFunction
  32. {
  33. /**
  34. * Get function docblock
  35. *
  36. * @param string $reflectionClass Name of reflection class to use
  37. * @return Zend_Reflection_Docblock
  38. */
  39. public function getDocblock($reflectionClass = 'Zend_Reflection_Docblock')
  40. {
  41. if ('' == ($comment = $this->getDocComment())) {
  42. require_once 'Zend/Reflection/Exception.php';
  43. throw new Zend_Reflection_Exception($this->getName() . ' does not have a docblock');
  44. }
  45. $instance = new $reflectionClass($comment);
  46. if (!$instance instanceof Zend_Reflection_Docblock) {
  47. require_once 'Zend/Reflection/Exception.php';
  48. throw new Zend_Reflection_Exception('Invalid reflection class provided; must extend Zend_Reflection_Docblock');
  49. }
  50. return $instance;
  51. }
  52. /**
  53. * Get start line (position) of function
  54. *
  55. * @param bool $includeDocComment
  56. * @return int
  57. */
  58. public function getStartLine($includeDocComment = false)
  59. {
  60. if ($includeDocComment) {
  61. if ($this->getDocComment() != '') {
  62. return $this->getDocblock()->getStartLine();
  63. }
  64. }
  65. return parent::getStartLine();
  66. }
  67. /**
  68. * Get contents of function
  69. *
  70. * @param bool $includeDocblock
  71. * @return string
  72. */
  73. public function getContents($includeDocblock = true)
  74. {
  75. return implode("\n",
  76. array_splice(
  77. file($this->getFileName()),
  78. $this->getStartLine($includeDocblock),
  79. ($this->getEndLine() - $this->getStartLine()),
  80. true
  81. )
  82. );
  83. }
  84. /**
  85. * Get function parameters
  86. *
  87. * @param string $reflectionClass Name of reflection class to use
  88. * @return array Array of Zend_Reflection_Parameter
  89. */
  90. public function getParameters($reflectionClass = 'Zend_Reflection_Parameter')
  91. {
  92. $phpReflections = parent::getParameters();
  93. $zendReflections = array();
  94. while ($phpReflections && ($phpReflection = array_shift($phpReflections))) {
  95. $instance = new $reflectionClass($this->getName(), $phpReflection->getName());
  96. if (!$instance instanceof Zend_Reflection_Parameter) {
  97. require_once 'Zend/Reflection/Exception.php';
  98. throw new Zend_Reflection_Exception('Invalid reflection class provided; must extend Zend_Reflection_Parameter');
  99. }
  100. $zendReflections[] = $instance;
  101. unset($phpReflection);
  102. }
  103. unset($phpReflections);
  104. return $zendReflections;
  105. }
  106. /**
  107. * Get return type tag
  108. *
  109. * @return Zend_Reflection_Docblock_Tag_Return
  110. */
  111. public function getReturn()
  112. {
  113. $docblock = $this->getDocblock();
  114. if (!$docblock->hasTag('return')) {
  115. require_once 'Zend/Reflection/Exception.php';
  116. throw new Zend_Reflection_Exception('Function does not specify an @return annotation tag; cannot determine return type');
  117. }
  118. $tag = $docblock->getTag('return');
  119. $return = Zend_Reflection_Docblock_Tag::factory('@return ' . $tag->getDescription());
  120. return $return;
  121. }
  122. }