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_Property
0024  */
0025 // require_once 'Zend/Reflection/Property.php';
0026 
0027 /**
0028  * @see Zend_Reflection_Method
0029  */
0030 // require_once 'Zend/Reflection/Method.php';
0031 
0032 /**
0033  * Zend_Reflection_Docblock
0034  */
0035 // require_once 'Zend/Reflection/Docblock.php';
0036 
0037 /**
0038  * @category   Zend
0039  * @package    Zend_Reflection
0040  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0041  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0042  */
0043 class Zend_Reflection_Class extends ReflectionClass
0044 {
0045     /**
0046      * Return the reflection file of the declaring file.
0047      *
0048      * @return Zend_Reflection_File
0049      */
0050     public function getDeclaringFile($reflectionClass = 'Zend_Reflection_File')
0051     {
0052         $instance = new $reflectionClass($this->getFileName());
0053         if (!$instance instanceof Zend_Reflection_File) {
0054             // require_once 'Zend/Reflection/Exception.php';
0055             throw new Zend_Reflection_Exception('Invalid reflection class specified; must extend Zend_Reflection_File');
0056         }
0057         return $instance;
0058     }
0059 
0060     /**
0061      * Return the classes Docblock reflection object
0062      *
0063      * @param  string $reflectionClass Name of reflection class to use
0064      * @return Zend_Reflection_Docblock
0065      * @throws Zend_Reflection_Exception for missing docblock or invalid reflection class
0066      */
0067     public function getDocblock($reflectionClass = 'Zend_Reflection_Docblock')
0068     {
0069         if ('' == $this->getDocComment()) {
0070             // require_once 'Zend/Reflection/Exception.php';
0071             throw new Zend_Reflection_Exception($this->getName() . ' does not have a docblock');
0072         }
0073 
0074         $instance = new $reflectionClass($this);
0075         if (!$instance instanceof Zend_Reflection_Docblock) {
0076             // require_once 'Zend/Reflection/Exception.php';
0077             throw new Zend_Reflection_Exception('Invalid reflection class specified; must extend Zend_Reflection_Docblock');
0078         }
0079         return $instance;
0080     }
0081 
0082     /**
0083      * Return the start line of the class
0084      *
0085      * @param bool $includeDocComment
0086      * @return int
0087      */
0088     public function getStartLine($includeDocComment = false)
0089     {
0090         if ($includeDocComment) {
0091             if ($this->getDocComment() != '') {
0092                 return $this->getDocblock()->getStartLine();
0093             }
0094         }
0095 
0096         return parent::getStartLine();
0097     }
0098 
0099     /**
0100      * Return the contents of the class
0101      *
0102      * @param bool $includeDocblock
0103      * @return string
0104      */
0105     public function getContents($includeDocblock = true)
0106     {
0107         $filename  = $this->getFileName();
0108         $filelines = file($filename);
0109         $startnum  = $this->getStartLine($includeDocblock);
0110         $endnum    = $this->getEndLine() - $this->getStartLine();
0111 
0112         return implode('', array_splice($filelines, $startnum, $endnum, true));
0113     }
0114 
0115     /**
0116      * Get all reflection objects of implemented interfaces
0117      *
0118      * @param  string $reflectionClass Name of reflection class to use
0119      * @return array Array of Zend_Reflection_Class
0120      */
0121     public function getInterfaces($reflectionClass = 'Zend_Reflection_Class')
0122     {
0123         $phpReflections  = parent::getInterfaces();
0124         $zendReflections = array();
0125         while ($phpReflections && ($phpReflection = array_shift($phpReflections))) {
0126             $instance = new $reflectionClass($phpReflection->getName());
0127             if (!$instance instanceof Zend_Reflection_Class) {
0128                 // require_once 'Zend/Reflection/Exception.php';
0129                 throw new Zend_Reflection_Exception('Invalid reflection class specified; must extend Zend_Reflection_Class');
0130             }
0131             $zendReflections[] = $instance;
0132             unset($phpReflection);
0133         }
0134         unset($phpReflections);
0135         return $zendReflections;
0136     }
0137 
0138     /**
0139      * Return method reflection by name
0140      *
0141      * @param  string $name
0142      * @param  string $reflectionClass Reflection class to utilize
0143      * @return Zend_Reflection_Method
0144      */
0145     public function getMethod($name, $reflectionClass = 'Zend_Reflection_Method')
0146     {
0147         $phpReflection  = parent::getMethod($name);
0148         $zendReflection = new $reflectionClass($this->getName(), $phpReflection->getName());
0149 
0150         if (!$zendReflection instanceof Zend_Reflection_Method) {
0151             // require_once 'Zend/Reflection/Exception.php';
0152             throw new Zend_Reflection_Exception('Invalid reflection class specified; must extend Zend_Reflection_Method');
0153         }
0154 
0155         unset($phpReflection);
0156         return $zendReflection;
0157     }
0158 
0159     /**
0160      * Get reflection objects of all methods
0161      *
0162      * @param  string $filter
0163      * @param  string $reflectionClass Reflection class to use for methods
0164      * @return array Array of Zend_Reflection_Method objects
0165      */
0166     public function getMethods($filter = -1, $reflectionClass = 'Zend_Reflection_Method')
0167     {
0168         $phpReflections  = parent::getMethods($filter);
0169         $zendReflections = array();
0170         while ($phpReflections && ($phpReflection = array_shift($phpReflections))) {
0171             $instance = new $reflectionClass($this->getName(), $phpReflection->getName());
0172             if (!$instance instanceof Zend_Reflection_Method) {
0173                 // require_once 'Zend/Reflection/Exception.php';
0174                 throw new Zend_Reflection_Exception('Invalid reflection class specified; must extend Zend_Reflection_Method');
0175             }
0176             $zendReflections[] = $instance;
0177             unset($phpReflection);
0178         }
0179         unset($phpReflections);
0180         return $zendReflections;
0181     }
0182 
0183     /**
0184      * Get parent reflection class of reflected class
0185      *
0186      * @param  string $reflectionClass Name of Reflection class to use
0187      * @return Zend_Reflection_Class
0188      */
0189     public function getParentClass($reflectionClass = 'Zend_Reflection_Class')
0190     {
0191         $phpReflection = parent::getParentClass();
0192         if ($phpReflection) {
0193             $zendReflection = new $reflectionClass($phpReflection->getName());
0194             if (!$zendReflection instanceof Zend_Reflection_Class) {
0195                 // require_once 'Zend/Reflection/Exception.php';
0196                 throw new Zend_Reflection_Exception('Invalid reflection class specified; must extend Zend_Reflection_Class');
0197             }
0198             unset($phpReflection);
0199             return $zendReflection;
0200         } else {
0201             return false;
0202         }
0203     }
0204 
0205     /**
0206      * Return reflection property of this class by name
0207      *
0208      * @param  string $name
0209      * @param  string $reflectionClass Name of reflection class to use
0210      * @return Zend_Reflection_Property
0211      */
0212     public function getProperty($name, $reflectionClass = 'Zend_Reflection_Property')
0213     {
0214         $phpReflection  = parent::getProperty($name);
0215         $zendReflection = new $reflectionClass($this->getName(), $phpReflection->getName());
0216         if (!$zendReflection instanceof Zend_Reflection_Property) {
0217             // require_once 'Zend/Reflection/Exception.php';
0218             throw new Zend_Reflection_Exception('Invalid reflection class specified; must extend Zend_Reflection_Property');
0219         }
0220         unset($phpReflection);
0221         return $zendReflection;
0222     }
0223 
0224     /**
0225      * Return reflection properties of this class
0226      *
0227      * @param  int $filter
0228      * @param  string $reflectionClass Name of reflection class to use
0229      * @return array Array of Zend_Reflection_Property
0230      */
0231     public function getProperties($filter = -1, $reflectionClass = 'Zend_Reflection_Property')
0232     {
0233         $phpReflections = parent::getProperties($filter);
0234         $zendReflections = array();
0235         while ($phpReflections && ($phpReflection = array_shift($phpReflections))) {
0236             $instance = new $reflectionClass($this->getName(), $phpReflection->getName());
0237             if (!$instance instanceof Zend_Reflection_Property) {
0238                 // require_once 'Zend/Reflection/Exception.php';
0239                 throw new Zend_Reflection_Exception('Invalid reflection class specified; must extend Zend_Reflection_Property');
0240             }
0241             $zendReflections[] = $instance;
0242             unset($phpReflection);
0243         }
0244         unset($phpReflections);
0245         return $zendReflections;
0246     }
0247 }