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  * @category   Zend
0024  * @package    Zend_Reflection
0025  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0026  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0027  */
0028 class Zend_Reflection_Parameter extends ReflectionParameter
0029 {
0030     /**
0031      * @var bool
0032      */
0033     protected $_isFromMethod = false;
0034 
0035     /**
0036      * Get declaring class reflection object
0037      *
0038      * @param  string $reflectionClass Reflection class to use
0039      * @return Zend_Reflection_Class
0040      */
0041     public function getDeclaringClass($reflectionClass = 'Zend_Reflection_Class')
0042     {
0043         $phpReflection  = parent::getDeclaringClass();
0044         $zendReflection = new $reflectionClass($phpReflection->getName());
0045         if (!$zendReflection instanceof Zend_Reflection_Class) {
0046             // require_once 'Zend/Reflection/Exception.php';
0047             throw new Zend_Reflection_Exception('Invalid reflection class provided; must extend Zend_Reflection_Class');
0048         }
0049         unset($phpReflection);
0050         return $zendReflection;
0051     }
0052 
0053     /**
0054      * Get class reflection object
0055      *
0056      * @param  string $reflectionClass Reflection class to use
0057      * @return Zend_Reflection_Class
0058      */
0059     public function getClass($reflectionClass = 'Zend_Reflection_Class')
0060     {
0061         $phpReflection  = parent::getClass();
0062         if($phpReflection == null) {
0063             return null;
0064         }
0065 
0066         $zendReflection = new $reflectionClass($phpReflection->getName());
0067         if (!$zendReflection instanceof Zend_Reflection_Class) {
0068             // require_once 'Zend/Reflection/Exception.php';
0069             throw new Zend_Reflection_Exception('Invalid reflection class provided; must extend Zend_Reflection_Class');
0070         }
0071         unset($phpReflection);
0072         return $zendReflection;
0073     }
0074 
0075     /**
0076      * Get declaring function reflection object
0077      *
0078      * @param  string $reflectionClass Reflection class to use
0079      * @return Zend_Reflection_Function|Zend_Reflection_Method
0080      */
0081     public function getDeclaringFunction($reflectionClass = null)
0082     {
0083         $phpReflection = parent::getDeclaringFunction();
0084         if ($phpReflection instanceof ReflectionMethod) {
0085             $baseClass = 'Zend_Reflection_Method';
0086             if (null === $reflectionClass) {
0087                 $reflectionClass = $baseClass;
0088             }
0089             $zendReflection = new $reflectionClass($this->getDeclaringClass()->getName(), $phpReflection->getName());
0090         } else {
0091             $baseClass = 'Zend_Reflection_Function';
0092             if (null === $reflectionClass) {
0093                 $reflectionClass = $baseClass;
0094             }
0095             $zendReflection = new $reflectionClass($phpReflection->getName());
0096         }
0097         if (!$zendReflection instanceof $baseClass) {
0098             // require_once 'Zend/Reflection/Exception.php';
0099             throw new Zend_Reflection_Exception('Invalid reflection class provided; must extend ' . $baseClass);
0100         }
0101         unset($phpReflection);
0102         return $zendReflection;
0103     }
0104 
0105     /**
0106      * Get parameter type
0107      *
0108      * @return string
0109      */
0110     public function getType()
0111     {
0112         if ($docblock = $this->getDeclaringFunction()->getDocblock()) {
0113             $params = $docblock->getTags('param');
0114 
0115             if (isset($params[$this->getPosition()])) {
0116                 return $params[$this->getPosition()]->getType();
0117             }
0118 
0119         }
0120 
0121         return null;
0122     }
0123 }