Verzeichnisstruktur phpBB-3.2.0
- Veröffentlicht
- 06.01.2017
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
ClassReflection.php
001 <?php
002 /**
003 * Zend Framework (http://framework.zend.com/)
004 *
005 * @link http://github.com/zendframework/zf2 for the canonical source repository
006 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
007 * @license http://framework.zend.com/license/new-bsd New BSD License
008 */
009
010 namespace Zend\Code\Reflection;
011
012 use ReflectionClass;
013 use Zend\Code\Annotation\AnnotationCollection;
014 use Zend\Code\Annotation\AnnotationManager;
015 use Zend\Code\Scanner\AnnotationScanner;
016 use Zend\Code\Scanner\FileScanner;
017
018 class ClassReflection extends ReflectionClass implements ReflectionInterface
019 {
020 /**
021 * @var AnnotationScanner
022 */
023 protected $annotations = null;
024
025 /**
026 * @var DocBlockReflection
027 */
028 protected $docBlock = null;
029
030 /**
031 * Return the reflection file of the declaring file.
032 *
033 * @return FileReflection
034 */
035 public function getDeclaringFile()
036 {
037 $instance = new FileReflection($this->getFileName());
038
039 return $instance;
040 }
041
042 /**
043 * Return the classes DocBlock reflection object
044 *
045 * @return DocBlockReflection
046 * @throws Exception\ExceptionInterface for missing DocBock or invalid reflection class
047 */
048 public function getDocBlock()
049 {
050 if (isset($this->docBlock)) {
051 return $this->docBlock;
052 }
053
054 if ('' == $this->getDocComment()) {
055 return false;
056 }
057
058 $this->docBlock = new DocBlockReflection($this);
059
060 return $this->docBlock;
061 }
062
063 /**
064 * @param AnnotationManager $annotationManager
065 * @return AnnotationCollection
066 */
067 public function getAnnotations(AnnotationManager $annotationManager)
068 {
069 $docComment = $this->getDocComment();
070
071 if ($docComment == '') {
072 return false;
073 }
074
075 if ($this->annotations) {
076 return $this->annotations;
077 }
078
079 $fileScanner = $this->createFileScanner($this->getFileName());
080 $nameInformation = $fileScanner->getClassNameInformation($this->getName());
081
082 if (!$nameInformation) {
083 return false;
084 }
085
086 $this->annotations = new AnnotationScanner($annotationManager, $docComment, $nameInformation);
087
088 return $this->annotations;
089 }
090
091 /**
092 * Return the start line of the class
093 *
094 * @param bool $includeDocComment
095 * @return int
096 */
097 public function getStartLine($includeDocComment = false)
098 {
099 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 }
284