[ Index ] |
PHP Cross Reference of phpBB-3.2.11-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Zend Framework (http://framework.zend.com/) 4 * 5 * @link http://github.com/zendframework/zf2 for the canonical source repository 6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 7 * @license http://framework.zend.com/license/new-bsd New BSD License 8 */ 9 10 namespace Zend\Code\Reflection; 11 12 use ReflectionClass; 13 use Zend\Code\Annotation\AnnotationCollection; 14 use Zend\Code\Annotation\AnnotationManager; 15 use Zend\Code\Scanner\AnnotationScanner; 16 use Zend\Code\Scanner\FileScanner; 17 18 class ClassReflection extends ReflectionClass implements ReflectionInterface 19 { 20 /** 21 * @var AnnotationScanner 22 */ 23 protected $annotations = null; 24 25 /** 26 * @var DocBlockReflection 27 */ 28 protected $docBlock = null; 29 30 /** 31 * Return the reflection file of the declaring file. 32 * 33 * @return FileReflection 34 */ 35 public function getDeclaringFile() 36 { 37 $instance = new FileReflection($this->getFileName()); 38 39 return $instance; 40 } 41 42 /** 43 * Return the classes DocBlock reflection object 44 * 45 * @return DocBlockReflection 46 * @throws Exception\ExceptionInterface for missing DocBock or invalid reflection class 47 */ 48 public function getDocBlock() 49 { 50 if (isset($this->docBlock)) { 51 return $this->docBlock; 52 } 53 54 if ('' == $this->getDocComment()) { 55 return false; 56 } 57 58 $this->docBlock = new DocBlockReflection($this); 59 60 return $this->docBlock; 61 } 62 63 /** 64 * @param AnnotationManager $annotationManager 65 * @return AnnotationCollection 66 */ 67 public function getAnnotations(AnnotationManager $annotationManager) 68 { 69 $docComment = $this->getDocComment(); 70 71 if ($docComment == '') { 72 return false; 73 } 74 75 if ($this->annotations) { 76 return $this->annotations; 77 } 78 79 $fileScanner = $this->createFileScanner($this->getFileName()); 80 $nameInformation = $fileScanner->getClassNameInformation($this->getName()); 81 82 if (!$nameInformation) { 83 return false; 84 } 85 86 $this->annotations = new AnnotationScanner($annotationManager, $docComment, $nameInformation); 87 88 return $this->annotations; 89 } 90 91 /** 92 * Return the start line of the class 93 * 94 * @param bool $includeDocComment 95 * @return int 96 */ 97 public function getStartLine($includeDocComment = false) 98 { 99 if ($includeDocComment && $this->getDocComment() != '') { 100 return $this->getDocBlock()->getStartLine(); 101 } 102 103 return parent::getStartLine(); 104 } 105 106 /** 107 * Return the contents of the class 108 * 109 * @param bool $includeDocBlock 110 * @return string 111 */ 112 public function getContents($includeDocBlock = true) 113 { 114 $fileName = $this->getFileName(); 115 116 if (false === $fileName || ! file_exists($fileName)) { 117 return ''; 118 } 119 120 $filelines = file($fileName); 121 $startnum = $this->getStartLine($includeDocBlock); 122 $endnum = $this->getEndLine() - $this->getStartLine(); 123 124 // Ensure we get between the open and close braces 125 $lines = array_slice($filelines, $startnum, $endnum); 126 array_unshift($lines, $filelines[$startnum-1]); 127 128 return strstr(implode('', $lines), '{'); 129 } 130 131 /** 132 * Get all reflection objects of implemented interfaces 133 * 134 * @return ClassReflection[] 135 */ 136 public function getInterfaces() 137 { 138 $phpReflections = parent::getInterfaces(); 139 $zendReflections = array(); 140 while ($phpReflections && ($phpReflection = array_shift($phpReflections))) { 141 $instance = new ClassReflection($phpReflection->getName()); 142 $zendReflections[] = $instance; 143 unset($phpReflection); 144 } 145 unset($phpReflections); 146 147 return $zendReflections; 148 } 149 150 /** 151 * Return method reflection by name 152 * 153 * @param string $name 154 * @return MethodReflection 155 */ 156 public function getMethod($name) 157 { 158 $method = new MethodReflection($this->getName(), parent::getMethod($name)->getName()); 159 160 return $method; 161 } 162 163 /** 164 * Get reflection objects of all methods 165 * 166 * @param int $filter 167 * @return MethodReflection[] 168 */ 169 public function getMethods($filter = -1) 170 { 171 $methods = array(); 172 foreach (parent::getMethods($filter) as $method) { 173 $instance = new MethodReflection($this->getName(), $method->getName()); 174 $methods[] = $instance; 175 } 176 177 return $methods; 178 } 179 180 /** 181 * Returns an array of reflection classes of traits used by this class. 182 * 183 * @return array|null 184 */ 185 public function getTraits() 186 { 187 $vals = array(); 188 $traits = parent::getTraits(); 189 if ($traits === null) { 190 return; 191 } 192 193 foreach ($traits as $trait) { 194 $vals[] = new ClassReflection($trait->getName()); 195 } 196 197 return $vals; 198 } 199 200 /** 201 * Get parent reflection class of reflected class 202 * 203 * @return ClassReflection|bool 204 */ 205 public function getParentClass() 206 { 207 $phpReflection = parent::getParentClass(); 208 if ($phpReflection) { 209 $zendReflection = new ClassReflection($phpReflection->getName()); 210 unset($phpReflection); 211 212 return $zendReflection; 213 } 214 215 return false; 216 } 217 218 /** 219 * Return reflection property of this class by name 220 * 221 * @param string $name 222 * @return PropertyReflection 223 */ 224 public function getProperty($name) 225 { 226 $phpReflection = parent::getProperty($name); 227 $zendReflection = new PropertyReflection($this->getName(), $phpReflection->getName()); 228 unset($phpReflection); 229 230 return $zendReflection; 231 } 232 233 /** 234 * Return reflection properties of this class 235 * 236 * @param int $filter 237 * @return PropertyReflection[] 238 */ 239 public function getProperties($filter = -1) 240 { 241 $phpReflections = parent::getProperties($filter); 242 $zendReflections = array(); 243 while ($phpReflections && ($phpReflection = array_shift($phpReflections))) { 244 $instance = new PropertyReflection($this->getName(), $phpReflection->getName()); 245 $zendReflections[] = $instance; 246 unset($phpReflection); 247 } 248 unset($phpReflections); 249 250 return $zendReflections; 251 } 252 253 /** 254 * @return string 255 */ 256 public function toString() 257 { 258 return parent::__toString(); 259 } 260 261 /** 262 * @return string 263 */ 264 public function __toString() 265 { 266 return parent::__toString(); 267 } 268 269 /** 270 * Creates a new FileScanner instance. 271 * 272 * By having this as a seperate method it allows the method to be overridden 273 * if a different FileScanner is needed. 274 * 275 * @param string $filename 276 * 277 * @return FileScanner 278 */ 279 protected function createFileScanner($filename) 280 { 281 return new FileScanner($filename); 282 } 283 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 11 20:33:01 2020 | Cross-referenced by PHPXref 0.7.1 |