File indexing completed on 2024-05-12 06:02:55

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_Reflection
0017  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0018  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0019  * @version    $Id$
0020  */
0021 
0022 /**
0023  * @see Zend_Reflection_Parameter
0024  */
0025 // require_once 'Zend/Reflection/Parameter.php';
0026 
0027 /**
0028  * @category   Zend
0029  * @package    Zend_Reflection
0030  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0031  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0032  */
0033 class Zend_Reflection_Function extends ReflectionFunction
0034 {
0035     /**
0036      * Get function docblock
0037      *
0038      * @param  string $reflectionClass Name of reflection class to use
0039      * @return Zend_Reflection_Docblock
0040      */
0041     public function getDocblock($reflectionClass = 'Zend_Reflection_Docblock')
0042     {
0043         if ('' == ($comment = $this->getDocComment())) {
0044             // require_once 'Zend/Reflection/Exception.php';
0045             throw new Zend_Reflection_Exception($this->getName() . ' does not have a docblock');
0046         }
0047         $instance = new $reflectionClass($comment);
0048         if (!$instance instanceof Zend_Reflection_Docblock) {
0049             // require_once 'Zend/Reflection/Exception.php';
0050             throw new Zend_Reflection_Exception('Invalid reflection class provided; must extend Zend_Reflection_Docblock');
0051         }
0052         return $instance;
0053     }
0054 
0055     /**
0056      * Get start line (position) of function
0057      *
0058      * @param  bool $includeDocComment
0059      * @return int
0060      */
0061     public function getStartLine($includeDocComment = false)
0062     {
0063         if ($includeDocComment) {
0064             if ($this->getDocComment() != '') {
0065                 return $this->getDocblock()->getStartLine();
0066             }
0067         }
0068 
0069         return parent::getStartLine();
0070     }
0071 
0072     /**
0073      * Get contents of function
0074      *
0075      * @param  bool $includeDocblock
0076      * @return string
0077      */
0078     public function getContents($includeDocblock = true)
0079     {
0080         return implode("\n",
0081             array_splice(
0082                 file($this->getFileName()),
0083                 $this->getStartLine($includeDocblock),
0084                 ($this->getEndLine() - $this->getStartLine()),
0085                 true
0086                 )
0087             );
0088     }
0089 
0090     /**
0091      * Get function parameters
0092      *
0093      * @param  string $reflectionClass Name of reflection class to use
0094      * @return array Array of Zend_Reflection_Parameter
0095      */
0096     public function getParameters($reflectionClass = 'Zend_Reflection_Parameter')
0097     {
0098         $phpReflections  = parent::getParameters();
0099         $zendReflections = array();
0100         while ($phpReflections && ($phpReflection = array_shift($phpReflections))) {
0101             $instance = new $reflectionClass($this->getName(), $phpReflection->getName());
0102             if (!$instance instanceof Zend_Reflection_Parameter) {
0103                 // require_once 'Zend/Reflection/Exception.php';
0104                 throw new Zend_Reflection_Exception('Invalid reflection class provided; must extend Zend_Reflection_Parameter');
0105             }
0106             $zendReflections[] = $instance;
0107             unset($phpReflection);
0108         }
0109         unset($phpReflections);
0110         return $zendReflections;
0111     }
0112 
0113     /**
0114      * Get return type tag
0115      *
0116      * @return Zend_Reflection_Docblock_Tag_Return
0117      */
0118     public function getReturn()
0119     {
0120         $docblock = $this->getDocblock();
0121         if (!$docblock->hasTag('return')) {
0122             // require_once 'Zend/Reflection/Exception.php';
0123             throw new Zend_Reflection_Exception('Function does not specify an @return annotation tag; cannot determine return type');
0124         }
0125         $tag    = $docblock->getTag('return');
0126         $return = Zend_Reflection_Docblock_Tag::factory('@return ' . $tag->getDescription());
0127         return $return;
0128     }
0129 }