1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
|
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Reflection
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Class.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* @see Zend_Reflection_Property
*/
require_once 'Zend/Reflection/Property.php';
/**
* @see Zend_Reflection_Method
*/
require_once 'Zend/Reflection/Method.php';
/**
* Zend_Reflection_Docblock
*/
require_once 'Zend/Reflection/Docblock.php';
/**
* @category Zend
* @package Zend_Reflection
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Reflection_Class extends ReflectionClass
{
/**
* Return the reflection file of the declaring file.
*
* @return Zend_Reflection_File
*/
public function getDeclaringFile($reflectionClass = 'Zend_Reflection_File')
{
$instance = new $reflectionClass($this->getFileName());
if (!$instance instanceof Zend_Reflection_File) {
require_once 'Zend/Reflection/Exception.php';
throw new Zend_Reflection_Exception('Invalid reflection class specified; must extend Zend_Reflection_File');
}
return $instance;
}
/**
* Return the classes Docblock reflection object
*
* @param string $reflectionClass Name of reflection class to use
* @return Zend_Reflection_Docblock
* @throws Zend_Reflection_Exception for missing docblock or invalid reflection class
*/
public function getDocblock($reflectionClass = 'Zend_Reflection_Docblock')
{
if ('' == $this->getDocComment()) {
require_once 'Zend/Reflection/Exception.php';
throw new Zend_Reflection_Exception($this->getName() . ' does not have a docblock');
}
$instance = new $reflectionClass($this);
if (!$instance instanceof Zend_Reflection_Docblock) {
require_once 'Zend/Reflection/Exception.php';
throw new Zend_Reflection_Exception('Invalid reflection class specified; must extend Zend_Reflection_Docblock');
}
return $instance;
}
/**
* Return the start line of the class
*
* @param bool $includeDocComment
* @return int
*/
public function getStartLine($includeDocComment = false)
{
if ($includeDocComment) {
if ($this->getDocComment() != '') {
return $this->getDocblock()->getStartLine();
}
}
return parent::getStartLine();
}
/**
* Return the contents of the class
*
* @param bool $includeDocblock
* @return string
*/
public function getContents($includeDocblock = true)
{
$filename = $this->getFileName();
$filelines = file($filename);
$startnum = $this->getStartLine($includeDocblock);
$endnum = $this->getEndLine() - $this->getStartLine();
return implode('', array_splice($filelines, $startnum, $endnum, true));
}
/**
* Get all reflection objects of implemented interfaces
*
* @param string $reflectionClass Name of reflection class to use
* @return array Array of Zend_Reflection_Class
*/
public function getInterfaces($reflectionClass = 'Zend_Reflection_Class')
{
$phpReflections = parent::getInterfaces();
$zendReflections = array();
while ($phpReflections && ($phpReflection = array_shift($phpReflections))) {
$instance = new $reflectionClass($phpReflection->getName());
if (!$instance instanceof Zend_Reflection_Class) {
require_once 'Zend/Reflection/Exception.php';
throw new Zend_Reflection_Exception('Invalid reflection class specified; must extend Zend_Reflection_Class');
}
$zendReflections[] = $instance;
unset($phpReflection);
}
unset($phpReflections);
return $zendReflections;
}
/**
* Return method reflection by name
*
* @param string $name
* @param string $reflectionClass Reflection class to utilize
* @return Zend_Reflection_Method
*/
public function getMethod($name, $reflectionClass = 'Zend_Reflection_Method')
{
$phpReflection = parent::getMethod($name);
$zendReflection = new $reflectionClass($this->getName(), $phpReflection->getName());
if (!$zendReflection instanceof Zend_Reflection_Method) {
require_once 'Zend/Reflection/Exception.php';
throw new Zend_Reflection_Exception('Invalid reflection class specified; must extend Zend_Reflection_Method');
}
unset($phpReflection);
return $zendReflection;
}
/**
* Get reflection objects of all methods
*
* @param string $filter
* @param string $reflectionClass Reflection class to use for methods
* @return array Array of Zend_Reflection_Method objects
*/
public function getMethods($filter = -1, $reflectionClass = 'Zend_Reflection_Method')
{
$phpReflections = parent::getMethods($filter);
$zendReflections = array();
while ($phpReflections && ($phpReflection = array_shift($phpReflections))) {
$instance = new $reflectionClass($this->getName(), $phpReflection->getName());
if (!$instance instanceof Zend_Reflection_Method) {
require_once 'Zend/Reflection/Exception.php';
throw new Zend_Reflection_Exception('Invalid reflection class specified; must extend Zend_Reflection_Method');
}
$zendReflections[] = $instance;
unset($phpReflection);
}
unset($phpReflections);
return $zendReflections;
}
/**
* Get parent reflection class of reflected class
*
* @param string $reflectionClass Name of Reflection class to use
* @return Zend_Reflection_Class
*/
public function getParentClass($reflectionClass = 'Zend_Reflection_Class')
{
$phpReflection = parent::getParentClass();
if ($phpReflection) {
$zendReflection = new $reflectionClass($phpReflection->getName());
if (!$zendReflection instanceof Zend_Reflection_Class) {
require_once 'Zend/Reflection/Exception.php';
throw new Zend_Reflection_Exception('Invalid reflection class specified; must extend Zend_Reflection_Class');
}
unset($phpReflection);
return $zendReflection;
} else {
return false;
}
}
/**
* Return reflection property of this class by name
*
* @param string $name
* @param string $reflectionClass Name of reflection class to use
* @return Zend_Reflection_Property
*/
public function getProperty($name, $reflectionClass = 'Zend_Reflection_Property')
{
$phpReflection = parent::getProperty($name);
$zendReflection = new $reflectionClass($this->getName(), $phpReflection->getName());
if (!$zendReflection instanceof Zend_Reflection_Property) {
require_once 'Zend/Reflection/Exception.php';
throw new Zend_Reflection_Exception('Invalid reflection class specified; must extend Zend_Reflection_Property');
}
unset($phpReflection);
return $zendReflection;
}
/**
* Return reflection properties of this class
*
* @param int $filter
* @param string $reflectionClass Name of reflection class to use
* @return array Array of Zend_Reflection_Property
*/
public function getProperties($filter = -1, $reflectionClass = 'Zend_Reflection_Property')
{
$phpReflections = parent::getProperties($filter);
$zendReflections = array();
while ($phpReflections && ($phpReflection = array_shift($phpReflections))) {
$instance = new $reflectionClass($this->getName(), $phpReflection->getName());
if (!$instance instanceof Zend_Reflection_Property) {
require_once 'Zend/Reflection/Exception.php';
throw new Zend_Reflection_Exception('Invalid reflection class specified; must extend Zend_Reflection_Property');
}
$zendReflections[] = $instance;
unset($phpReflection);
}
unset($phpReflections);
return $zendReflections;
}
}
|