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