web/lib/Zend/Reflection/Parameter.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: Parameter.php 20096 2010-01-06 02:05:09Z bkarwin $
       
    20  */
       
    21 
       
    22 /**
       
    23  * @category   Zend
       
    24  * @package    Zend_Reflection
       
    25  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    26  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    27  */
       
    28 class Zend_Reflection_Parameter extends ReflectionParameter
       
    29 {
       
    30     /**
       
    31      * @var bool
       
    32      */
       
    33     protected $_isFromMethod = false;
       
    34 
       
    35     /**
       
    36      * Get declaring class reflection object
       
    37      *
       
    38      * @param  string $reflectionClass Reflection class to use
       
    39      * @return Zend_Reflection_Class
       
    40      */
       
    41     public function getDeclaringClass($reflectionClass = 'Zend_Reflection_Class')
       
    42     {
       
    43         $phpReflection  = parent::getDeclaringClass();
       
    44         $zendReflection = new $reflectionClass($phpReflection->getName());
       
    45         if (!$zendReflection instanceof Zend_Reflection_Class) {
       
    46             require_once 'Zend/Reflection/Exception.php';
       
    47             throw new Zend_Reflection_Exception('Invalid reflection class provided; must extend Zend_Reflection_Class');
       
    48         }
       
    49         unset($phpReflection);
       
    50         return $zendReflection;
       
    51     }
       
    52 
       
    53     /**
       
    54      * Get class reflection object
       
    55      *
       
    56      * @param  string $reflectionClass Reflection class to use
       
    57      * @return Zend_Reflection_Class
       
    58      */
       
    59     public function getClass($reflectionClass = 'Zend_Reflection_Class')
       
    60     {
       
    61         $phpReflection  = parent::getClass();
       
    62         if($phpReflection == null) {
       
    63             return null;
       
    64         }
       
    65 
       
    66         $zendReflection = new $reflectionClass($phpReflection->getName());
       
    67         if (!$zendReflection instanceof Zend_Reflection_Class) {
       
    68             require_once 'Zend/Reflection/Exception.php';
       
    69             throw new Zend_Reflection_Exception('Invalid reflection class provided; must extend Zend_Reflection_Class');
       
    70         }
       
    71         unset($phpReflection);
       
    72         return $zendReflection;
       
    73     }
       
    74 
       
    75     /**
       
    76      * Get declaring function reflection object
       
    77      *
       
    78      * @param  string $reflectionClass Reflection class to use
       
    79      * @return Zend_Reflection_Function|Zend_Reflection_Method
       
    80      */
       
    81     public function getDeclaringFunction($reflectionClass = null)
       
    82     {
       
    83         $phpReflection = parent::getDeclaringFunction();
       
    84         if ($phpReflection instanceof ReflectionMethod) {
       
    85             $baseClass = 'Zend_Reflection_Method';
       
    86             if (null === $reflectionClass) {
       
    87                 $reflectionClass = $baseClass;
       
    88             }
       
    89             $zendReflection = new $reflectionClass($this->getDeclaringClass()->getName(), $phpReflection->getName());
       
    90         } else {
       
    91             $baseClass = 'Zend_Reflection_Function';
       
    92             if (null === $reflectionClass) {
       
    93                 $reflectionClass = $baseClass;
       
    94             }
       
    95             $zendReflection = new $reflectionClass($phpReflection->getName());
       
    96         }
       
    97         if (!$zendReflection instanceof $baseClass) {
       
    98             require_once 'Zend/Reflection/Exception.php';
       
    99             throw new Zend_Reflection_Exception('Invalid reflection class provided; must extend ' . $baseClass);
       
   100         }
       
   101         unset($phpReflection);
       
   102         return $zendReflection;
       
   103     }
       
   104 
       
   105     /**
       
   106      * Get parameter type
       
   107      *
       
   108      * @return string
       
   109      */
       
   110     public function getType()
       
   111     {
       
   112         if ($docblock = $this->getDeclaringFunction()->getDocblock()) {
       
   113             $params = $docblock->getTags('param');
       
   114 
       
   115             if (isset($params[$this->getPosition()])) {
       
   116                 return $params[$this->getPosition()]->getType();
       
   117             }
       
   118 
       
   119         }
       
   120 
       
   121         return null;
       
   122     }
       
   123 }