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

DocBlockScanner.php

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