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

FileReflection.php

Zuletzt modifiziert: 02.04.2025, 15:03 - Dateigröße: 7.18 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 Zend\Code\Scanner\CachingFileScanner;
013   
014  use function basename;
015  use function count;
016  use function current;
017  use function file_get_contents;
018  use function get_included_files;
019  use function in_array;
020  use function realpath;
021  use function reset;
022  use function sprintf;
023  use function stream_resolve_include_path;
024  use function substr_count;
025   
026  class FileReflection implements ReflectionInterface
027  {
028      /**
029       * @var string
030       */
031      protected $filePath;
032   
033      /**
034       * @var string
035       */
036      protected $docComment;
037   
038      /**
039       * @var int
040       */
041      protected $startLine = 1;
042   
043      /**
044       * @var int
045       */
046      protected $endLine;
047   
048      /**
049       * @var string[]
050       */
051      protected $namespaces = [];
052   
053      /**
054       * @var string[]
055       */
056      protected $uses = [];
057   
058      /**
059       * @var string[]
060       */
061      protected $requiredFiles = [];
062   
063      /**
064       * @var ClassReflection[]
065       */
066      protected $classes = [];
067   
068      /**
069       * @var FunctionReflection[]
070       */
071      protected $functions = [];
072   
073      /**
074       * @var string
075       */
076      protected $contents;
077   
078      /**
079       * @param  string $filename
080       * @param  bool $includeIfNotAlreadyIncluded
081       * @throws Exception\InvalidArgumentException If file does not exists
082       * @throws Exception\RuntimeException If file exists but is not included or required
083       */
084      public function __construct($filename, $includeIfNotAlreadyIncluded = false)
085      {
086          if (($fileRealPath = realpath($filename)) === false) {
087              $fileRealPath = stream_resolve_include_path($filename);
088          }
089   
090          if (! $fileRealPath) {
091              throw new Exception\InvalidArgumentException(sprintf(
092                  'No file for %s was found.',
093                  $filename
094              ));
095          }
096   
097          if (! in_array($fileRealPath, get_included_files())) {
098              if (! $includeIfNotAlreadyIncluded) {
099                  throw new Exception\RuntimeException(sprintf(
100                      'File %s must be required before it can be reflected',
101                      $filename
102                  ));
103              }
104   
105              include $fileRealPath;
106          }
107   
108          $this->filePath = $fileRealPath;
109          $this->reflect();
110      }
111   
112      /**
113       * Required by the Reflector interface.
114       *
115       * @todo   What should this do?
116       * @return void
117       */
118      public static function export()
119      {
120      }
121   
122      /**
123       * Return the file name of the reflected file
124       *
125       * @return string
126       */
127      public function getFileName()
128      {
129          return basename($this->filePath);
130      }
131   
132      /**
133       * Get the start line - Always 1, staying consistent with the Reflection API
134       *
135       * @return int
136       */
137      public function getStartLine()
138      {
139          return $this->startLine;
140      }
141   
142      /**
143       * Get the end line / number of lines
144       *
145       * @return int
146       */
147      public function getEndLine()
148      {
149          return $this->endLine;
150      }
151   
152      /**
153       * @return string
154       */
155      public function getDocComment()
156      {
157          return $this->docComment;
158      }
159   
160      /**
161       * @return DocBlockReflection|false
162       */
163      public function getDocBlock()
164      {
165          if (! ($docComment = $this->getDocComment())) {
166              return false;
167          }
168   
169          $instance = new DocBlockReflection($docComment);
170   
171          return $instance;
172      }
173   
174      /**
175       * @return string[]
176       */
177      public function getNamespaces()
178      {
179          return $this->namespaces;
180      }
181   
182      /**
183       * @return null|string
184       */
185      public function getNamespace()
186      {
187          if (count($this->namespaces) == 0) {
188              return;
189          }
190   
191          return $this->namespaces[0];
192      }
193   
194      /**
195       * @return array
196       */
197      public function getUses()
198      {
199          return $this->uses;
200      }
201   
202      /**
203       * Return the reflection classes of the classes found inside this file
204       *
205       * @return ClassReflection[]
206       */
207      public function getClasses()
208      {
209          $classes = [];
210          foreach ($this->classes as $class) {
211              $classes[] = new ClassReflection($class);
212          }
213   
214          return $classes;
215      }
216   
217      /**
218       * Return the reflection functions of the functions found inside this file
219       *
220       * @return FunctionReflection[]
221       */
222      public function getFunctions()
223      {
224          $functions = [];
225          foreach ($this->functions as $function) {
226              $functions[] = new FunctionReflection($function);
227          }
228   
229          return $functions;
230      }
231   
232      /**
233       * Retrieve the reflection class of a given class found in this file
234       *
235       * @param  null|string $name
236       * @return ClassReflection
237       * @throws Exception\InvalidArgumentException for invalid class name or invalid reflection class
238       */
239      public function getClass($name = null)
240      {
241          if (null === $name) {
242              reset($this->classes);
243              $selected = current($this->classes);
244   
245              return new ClassReflection($selected);
246          }
247   
248          if (in_array($name, $this->classes)) {
249              return new ClassReflection($name);
250          }
251   
252          throw new Exception\InvalidArgumentException(sprintf(
253              'Class by name %s not found.',
254              $name
255          ));
256      }
257   
258      /**
259       * Return the full contents of file
260       *
261       * @return string
262       */
263      public function getContents()
264      {
265          return file_get_contents($this->filePath);
266      }
267   
268      public function toString()
269      {
270          return ''; // @todo
271      }
272   
273      /**
274       * Serialize to string
275       *
276       * Required by the Reflector interface
277       *
278       * @todo   What should this serialization look like?
279       * @return string
280       */
281      public function __toString()
282      {
283          return '';
284      }
285   
286      /**
287       * This method does the work of "reflecting" the file
288       *
289       * Uses Zend\Code\Scanner\FileScanner to gather file information
290       *
291       * @return void
292       */
293      protected function reflect()
294      {
295          $scanner             = new CachingFileScanner($this->filePath);
296          $this->docComment    = $scanner->getDocComment();
297          $this->requiredFiles = $scanner->getIncludes();
298          $this->classes       = $scanner->getClassNames();
299          $this->namespaces    = $scanner->getNamespaces();
300          $this->uses          = $scanner->getUses();
301      }
302   
303      /**
304       * Validate / check a file level DocBlock
305       *
306       * @param  array $tokens Array of tokenizer tokens
307       * @return void
308       */
309      protected function checkFileDocBlock($tokens)
310      {
311          foreach ($tokens as $token) {
312              $type    = $token[0];
313              $value   = $token[1];
314              $lineNum = $token[2];
315              if (($type == T_OPEN_TAG) || ($type == T_WHITESPACE)) {
316                  continue;
317              } elseif ($type == T_DOC_COMMENT) {
318                  $this->docComment = $value;
319                  $this->startLine  = $lineNum + substr_count($value, "\n") + 1;
320   
321                  return;
322              } else {
323                  // Only whitespace is allowed before file DocBlocks
324                  return;
325              }
326          }
327      }
328  }
329