Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

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.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

ClassReflection.php

Zuletzt modifiziert: 02.04.2025, 15:03 - Dateigröße: 7.17 KiB


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-2016 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  use function array_shift;
019  use function array_slice;
020  use function array_unshift;
021  use function file;
022  use function file_exists;
023  use function implode;
024  use function strstr;
025   
026  class ClassReflection extends ReflectionClass implements ReflectionInterface
027  {
028      /**
029       * @var AnnotationScanner
030       */
031      protected $annotations;
032   
033      /**
034       * @var DocBlockReflection
035       */
036      protected $docBlock;
037   
038      /**
039       * Return the reflection file of the declaring file.
040       *
041       * @return FileReflection
042       */
043      public function getDeclaringFile()
044      {
045          $instance = new FileReflection($this->getFileName());
046   
047          return $instance;
048      }
049   
050      /**
051       * Return the classes DocBlock reflection object
052       *
053       * @return DocBlockReflection|false
054       * @throws Exception\ExceptionInterface for missing DocBock or invalid reflection class
055       */
056      public function getDocBlock()
057      {
058          if (isset($this->docBlock)) {
059              return $this->docBlock;
060          }
061   
062          if ('' == $this->getDocComment()) {
063              return false;
064          }
065   
066          $this->docBlock = new DocBlockReflection($this);
067   
068          return $this->docBlock;
069      }
070   
071      /**
072       * @param  AnnotationManager $annotationManager
073       * @return AnnotationCollection|false
074       */
075      public function getAnnotations(AnnotationManager $annotationManager)
076      {
077          $docComment = $this->getDocComment();
078   
079          if ($docComment == '') {
080              return false;
081          }
082   
083          if ($this->annotations) {
084              return $this->annotations;
085          }
086   
087          $fileScanner       = $this->createFileScanner($this->getFileName());
088          $nameInformation   = $fileScanner->getClassNameInformation($this->getName());
089   
090          if (! $nameInformation) {
091              return false;
092          }
093   
094          $this->annotations = new AnnotationScanner($annotationManager, $docComment, $nameInformation);
095   
096          return $this->annotations;
097      }
098   
099      /**
100       * Return the start line of the class
101       *
102       * @param  bool $includeDocComment
103       * @return int
104       */
105      public function getStartLine($includeDocComment = false)
106      {
107          if ($includeDocComment && $this->getDocComment() != '') {
108              return $this->getDocBlock()->getStartLine();
109          }
110   
111          return parent::getStartLine();
112      }
113   
114      /**
115       * Return the contents of the class
116       *
117       * @param  bool $includeDocBlock
118       * @return string
119       */
120      public function getContents($includeDocBlock = true)
121      {
122          $fileName = $this->getFileName();
123   
124          if (false === $fileName || ! file_exists($fileName)) {
125              return '';
126          }
127   
128          $filelines = file($fileName);
129          $startnum  = $this->getStartLine($includeDocBlock);
130          $endnum    = $this->getEndLine() - $this->getStartLine();
131   
132          // Ensure we get between the open and close braces
133          $lines = array_slice($filelines, $startnum, $endnum);
134          array_unshift($lines, $filelines[$startnum - 1]);
135   
136          return strstr(implode('', $lines), '{');
137      }
138   
139      /**
140       * Get all reflection objects of implemented interfaces
141       *
142       * @return ClassReflection[]
143       */
144      public function getInterfaces()
145      {
146          $phpReflections  = parent::getInterfaces();
147          $zendReflections = [];
148          while ($phpReflections && ($phpReflection = array_shift($phpReflections))) {
149              $instance          = new ClassReflection($phpReflection->getName());
150              $zendReflections[] = $instance;
151              unset($phpReflection);
152          }
153          unset($phpReflections);
154   
155          return $zendReflections;
156      }
157   
158      /**
159       * Return method reflection by name
160       *
161       * @param  string $name
162       * @return MethodReflection
163       */
164      public function getMethod($name)
165      {
166          $method = new MethodReflection($this->getName(), parent::getMethod($name)->getName());
167   
168          return $method;
169      }
170   
171      /**
172       * Get reflection objects of all methods
173       *
174       * @param  int $filter
175       * @return MethodReflection[]
176       */
177      public function getMethods($filter = -1)
178      {
179          $methods = [];
180          foreach (parent::getMethods($filter) as $method) {
181              $instance  = new MethodReflection($this->getName(), $method->getName());
182              $methods[] = $instance;
183          }
184   
185          return $methods;
186      }
187   
188      /**
189       * Returns an array of reflection classes of traits used by this class.
190       *
191       * @return null|array
192       */
193      public function getTraits()
194      {
195          $vals = [];
196          $traits = parent::getTraits();
197          if ($traits === null) {
198              return;
199          }
200   
201          foreach ($traits as $trait) {
202              $vals[] = new ClassReflection($trait->getName());
203          }
204   
205          return $vals;
206      }
207   
208      /**
209       * Get parent reflection class of reflected class
210       *
211       * @return ClassReflection|bool
212       */
213      public function getParentClass()
214      {
215          $phpReflection = parent::getParentClass();
216          if ($phpReflection) {
217              $zendReflection = new ClassReflection($phpReflection->getName());
218              unset($phpReflection);
219   
220              return $zendReflection;
221          }
222   
223          return false;
224      }
225   
226      /**
227       * Return reflection property of this class by name
228       *
229       * @param  string $name
230       * @return PropertyReflection
231       */
232      public function getProperty($name)
233      {
234          $phpReflection  = parent::getProperty($name);
235          $zendReflection = new PropertyReflection($this->getName(), $phpReflection->getName());
236          unset($phpReflection);
237   
238          return $zendReflection;
239      }
240   
241      /**
242       * Return reflection properties of this class
243       *
244       * @param  int $filter
245       * @return PropertyReflection[]
246       */
247      public function getProperties($filter = -1)
248      {
249          $phpReflections  = parent::getProperties($filter);
250          $zendReflections = [];
251          while ($phpReflections && ($phpReflection = array_shift($phpReflections))) {
252              $instance          = new PropertyReflection($this->getName(), $phpReflection->getName());
253              $zendReflections[] = $instance;
254              unset($phpReflection);
255          }
256          unset($phpReflections);
257   
258          return $zendReflections;
259      }
260   
261      /**
262       * @return string
263       */
264      public function toString()
265      {
266          return parent::__toString();
267      }
268   
269      /**
270       * @return string
271       */
272      public function __toString()
273      {
274          return parent::__toString();
275      }
276   
277      /**
278       * Creates a new FileScanner instance.
279       *
280       * By having this as a separate method it allows the method to be overridden
281       * if a different FileScanner is needed.
282       *
283       * @param  string $filename
284       *
285       * @return FileScanner
286       */
287      protected function createFileScanner($filename)
288      {
289          return new FileScanner($filename);
290      }
291  }
292