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