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

DocBlockScanner.php

Zuletzt modifiziert: 02.04.2025, 15:03 - Dateigröße: 10.12 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\Scanner;
011   
012  use Zend\Code\Annotation\AnnotationManager;
013  use Zend\Code\NameInformation;
014   
015  use function array_pop;
016  use function array_push;
017  use function current;
018  use function end;
019  use function key;
020  use function next;
021  use function preg_match;
022  use function reset;
023  use function strlen;
024  use function strpos;
025  use function substr;
026  use function trim;
027   
028  class DocBlockScanner implements ScannerInterface
029  {
030      /**
031       * @var bool
032       */
033      protected $isScanned = false;
034   
035      /**
036       * @var string
037       */
038      protected $docComment;
039   
040      /**
041       * @var NameInformation
042       */
043      protected $nameInformation;
044   
045      /**
046       * @var AnnotationManager
047       */
048      protected $annotationManager;
049   
050      /**
051       * @var string
052       */
053      protected $shortDescription;
054   
055      /**
056       * @var string
057       */
058      protected $longDescription = '';
059   
060      /**
061       * @var array
062       */
063      protected $tags = [];
064   
065      /**
066       * @var array
067       */
068      protected $annotations = [];
069   
070      /**
071       * @param  string $docComment
072       * @param null|NameInformation $nameInformation
073       */
074      public function __construct($docComment, NameInformation $nameInformation = null)
075      {
076          $this->docComment      = $docComment;
077          $this->nameInformation = $nameInformation;
078      }
079   
080      /**
081       * @return string
082       */
083      public function getShortDescription()
084      {
085          $this->scan();
086   
087          return $this->shortDescription;
088      }
089   
090      /**
091       * @return string
092       */
093      public function getLongDescription()
094      {
095          $this->scan();
096   
097          return $this->longDescription;
098      }
099   
100      /**
101       * @return array
102       */
103      public function getTags()
104      {
105          $this->scan();
106   
107          return $this->tags;
108      }
109   
110      /**
111       * @return array
112       */
113      public function getAnnotations()
114      {
115          $this->scan();
116   
117          return $this->annotations;
118      }
119   
120      /**
121       * @return void
122       */
123      protected function scan()
124      {
125          if ($this->isScanned) {
126              return;
127          }
128   
129          $mode = 1;
130   
131          $tokens   = $this->tokenize();
132          $tagIndex = null;
133          reset($tokens);
134   
135          SCANNER_TOP:
136          $token = current($tokens);
137   
138          switch ($token[0]) {
139              case 'DOCBLOCK_NEWLINE':
140                  if ($this->shortDescription != '' && $tagIndex === null) {
141                      $mode = 2;
142                  } else {
143                      $this->longDescription .= $token[1];
144                  }
145                  goto SCANNER_CONTINUE;
146                  //goto no break needed
147   
148              case 'DOCBLOCK_WHITESPACE':
149              case 'DOCBLOCK_TEXT':
150                  if ($tagIndex !== null) {
151                      $this->tags[$tagIndex]['value'] .= $this->tags[$tagIndex]['value'] == ''
152                          ? $token[1]
153                          : ' ' . $token[1];
154                      goto SCANNER_CONTINUE;
155                  } elseif ($mode <= 2) {
156                      if ($mode == 1) {
157                          $this->shortDescription .= $token[1];
158                      } else {
159                          $this->longDescription .= $token[1];
160                      }
161                      goto SCANNER_CONTINUE;
162                  }
163                  //gotos no break needed
164              case 'DOCBLOCK_TAG':
165                  array_push($this->tags, [
166                      'name'  => $token[1],
167                      'value' => '',
168                  ]);
169                  end($this->tags);
170                  $tagIndex = key($this->tags);
171                  $mode     = 3;
172                  goto SCANNER_CONTINUE;
173                  //goto no break needed
174   
175              case 'DOCBLOCK_COMMENTEND':
176                  goto SCANNER_END;
177          }
178   
179          SCANNER_CONTINUE:
180          if (next($tokens) === false) {
181              goto SCANNER_END;
182          }
183          goto SCANNER_TOP;
184   
185          SCANNER_END:
186   
187          $this->shortDescription = trim($this->shortDescription);
188          $this->longDescription  = trim($this->longDescription);
189          $this->isScanned        = true;
190      }
191   
192      /**
193       * @return array
194       */
195      protected function tokenize()
196      {
197          static $CONTEXT_INSIDE_DOCBLOCK = 0x01;
198          static $CONTEXT_INSIDE_ASTERISK = 0x02;
199   
200          $context     = 0x00;
201          $stream      = $this->docComment;
202          $streamIndex = null;
203          $tokens      = [];
204          $tokenIndex  = null;
205          $currentChar = null;
206          $currentWord = null;
207          $currentLine = null;
208   
209          $MACRO_STREAM_ADVANCE_CHAR = function ($positionsForward = 1) use (
210              &$stream,
211              &$streamIndex,
212              &$currentChar,
213              &$currentWord,
214              &$currentLine
215          ) {
216              $positionsForward = $positionsForward > 0 ? $positionsForward : 1;
217              $streamIndex      = $streamIndex === null ? 0 : $streamIndex + $positionsForward;
218              if (! isset($stream[$streamIndex])) {
219                  $currentChar = false;
220   
221                  return false;
222              }
223              $currentChar = $stream[$streamIndex];
224              $matches     = [];
225              $currentLine = preg_match('#(.*?)\r?\n#', $stream, $matches, null, $streamIndex) === 1
226                  ? $matches[1]
227                  : substr($stream, $streamIndex);
228              if ($currentChar === ' ') {
229                  $currentWord = preg_match('#( +)#', $currentLine, $matches) === 1 ? $matches[1] : $currentLine;
230              } else {
231                  $currentWord = ($matches = strpos($currentLine, ' ')) !== false
232                      ? substr($currentLine, 0, $matches)
233                      : $currentLine;
234              }
235   
236              return $currentChar;
237          };
238          $MACRO_STREAM_ADVANCE_WORD       = function () use (&$currentWord, &$MACRO_STREAM_ADVANCE_CHAR) {
239              return $MACRO_STREAM_ADVANCE_CHAR(strlen($currentWord));
240          };
241          $MACRO_STREAM_ADVANCE_LINE       = function () use (&$currentLine, &$MACRO_STREAM_ADVANCE_CHAR) {
242              return $MACRO_STREAM_ADVANCE_CHAR(strlen($currentLine));
243          };
244          $MACRO_TOKEN_ADVANCE             = function () use (&$tokenIndex, &$tokens) {
245              $tokenIndex          = $tokenIndex === null ? 0 : $tokenIndex + 1;
246              $tokens[$tokenIndex] = ['DOCBLOCK_UNKNOWN', ''];
247          };
248          $MACRO_TOKEN_SET_TYPE            = function ($type) use (&$tokenIndex, &$tokens) {
249              $tokens[$tokenIndex][0] = $type;
250          };
251          $MACRO_TOKEN_APPEND_CHAR         = function () use (&$currentChar, &$tokens, &$tokenIndex) {
252              $tokens[$tokenIndex][1] .= $currentChar;
253          };
254          $MACRO_TOKEN_APPEND_WORD         = function () use (&$currentWord, &$tokens, &$tokenIndex) {
255              $tokens[$tokenIndex][1] .= $currentWord;
256          };
257          $MACRO_TOKEN_APPEND_WORD_PARTIAL = function ($length) use (&$currentWord, &$tokens, &$tokenIndex) {
258              $tokens[$tokenIndex][1] .= substr($currentWord, 0, $length);
259          };
260          $MACRO_TOKEN_APPEND_LINE         = function () use (&$currentLine, &$tokens, &$tokenIndex) {
261              $tokens[$tokenIndex][1] .= $currentLine;
262          };
263   
264          $MACRO_STREAM_ADVANCE_CHAR();
265          $MACRO_TOKEN_ADVANCE();
266   
267          TOKENIZER_TOP:
268   
269          if ($context === 0x00 && $currentChar === '/' && $currentWord === '/**') {
270              $MACRO_TOKEN_SET_TYPE('DOCBLOCK_COMMENTSTART');
271              $MACRO_TOKEN_APPEND_WORD();
272              $MACRO_TOKEN_ADVANCE();
273              $context |= $CONTEXT_INSIDE_DOCBLOCK;
274              $context |= $CONTEXT_INSIDE_ASTERISK;
275              if ($MACRO_STREAM_ADVANCE_WORD() === false) {
276                  goto TOKENIZER_END;
277              }
278              goto TOKENIZER_TOP;
279          }
280   
281          if ($context & $CONTEXT_INSIDE_DOCBLOCK && $currentWord === '*/') {
282              $MACRO_TOKEN_SET_TYPE('DOCBLOCK_COMMENTEND');
283              $MACRO_TOKEN_APPEND_WORD();
284              $MACRO_TOKEN_ADVANCE();
285              $context &= ~$CONTEXT_INSIDE_DOCBLOCK;
286              if ($MACRO_STREAM_ADVANCE_WORD() === false) {
287                  goto TOKENIZER_END;
288              }
289              goto TOKENIZER_TOP;
290          }
291   
292          if ($currentChar === ' ' || $currentChar === "\t") {
293              $MACRO_TOKEN_SET_TYPE(
294                  $context & $CONTEXT_INSIDE_ASTERISK
295                  ? 'DOCBLOCK_WHITESPACE'
296                  : 'DOCBLOCK_WHITESPACE_INDENT'
297              );
298              $MACRO_TOKEN_APPEND_WORD();
299              $MACRO_TOKEN_ADVANCE();
300              if ($MACRO_STREAM_ADVANCE_WORD() === false) {
301                  goto TOKENIZER_END;
302              }
303              goto TOKENIZER_TOP;
304          }
305   
306          if ($currentChar === '*') {
307              if (($context & $CONTEXT_INSIDE_DOCBLOCK) && ($context & $CONTEXT_INSIDE_ASTERISK)) {
308                  $MACRO_TOKEN_SET_TYPE('DOCBLOCK_TEXT');
309              } else {
310                  $MACRO_TOKEN_SET_TYPE('DOCBLOCK_ASTERISK');
311                  $context |= $CONTEXT_INSIDE_ASTERISK;
312              }
313              $MACRO_TOKEN_APPEND_CHAR();
314              $MACRO_TOKEN_ADVANCE();
315              if ($MACRO_STREAM_ADVANCE_CHAR() === false) {
316                  goto TOKENIZER_END;
317              }
318              goto TOKENIZER_TOP;
319          }
320   
321          if ($currentChar === '@') {
322              $MACRO_TOKEN_SET_TYPE('DOCBLOCK_TAG');
323              $MACRO_TOKEN_APPEND_WORD();
324              $MACRO_TOKEN_ADVANCE();
325              if ($MACRO_STREAM_ADVANCE_WORD() === false) {
326                  goto TOKENIZER_END;
327              }
328              goto TOKENIZER_TOP;
329          }
330   
331          if ($currentChar === "\n") {
332              $MACRO_TOKEN_SET_TYPE('DOCBLOCK_NEWLINE');
333              $MACRO_TOKEN_APPEND_CHAR();
334              $MACRO_TOKEN_ADVANCE();
335              $context &= ~$CONTEXT_INSIDE_ASTERISK;
336              if ($MACRO_STREAM_ADVANCE_CHAR() === false) {
337                  goto TOKENIZER_END;
338              }
339              goto TOKENIZER_TOP;
340          }
341   
342          $MACRO_TOKEN_SET_TYPE('DOCBLOCK_TEXT');
343          $MACRO_TOKEN_APPEND_LINE();
344          $MACRO_TOKEN_ADVANCE();
345          if ($MACRO_STREAM_ADVANCE_LINE() === false) {
346              goto TOKENIZER_END;
347          }
348          goto TOKENIZER_TOP;
349   
350          TOKENIZER_END:
351   
352          array_pop($tokens);
353   
354          return $tokens;
355      }
356  }
357