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

DocBlockReflection.php

Zuletzt modifiziert: 09.10.2024, 12:57 - Dateigröße: 6.81 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 Reflector;
 013  use Zend\Code\Reflection\DocBlock\Tag\TagInterface as DocBlockTagInterface;
 014  use Zend\Code\Reflection\DocBlock\TagManager as DocBlockTagManager;
 015  use Zend\Code\Scanner\DocBlockScanner;
 016   
 017  class DocBlockReflection implements ReflectionInterface
 018  {
 019      /**
 020       * @var Reflector
 021       */
 022      protected $reflector = null;
 023   
 024      /**
 025       * @var string
 026       */
 027      protected $docComment = null;
 028   
 029      /**
 030       * @var DocBlockTagManager
 031       */
 032      protected $tagManager = null;
 033   
 034      /**#@+
 035       * @var int
 036       */
 037      protected $startLine = null;
 038      protected $endLine = null;
 039      /**#@-*/
 040   
 041      /**
 042       * @var string
 043       */
 044      protected $cleanDocComment = null;
 045   
 046      /**
 047       * @var string
 048       */
 049      protected $longDescription = null;
 050   
 051      /**
 052       * @var string
 053       */
 054      protected $shortDescription = null;
 055   
 056      /**
 057       * @var array
 058       */
 059      protected $tags = array();
 060   
 061      /**
 062       * @var bool
 063       */
 064      protected $isReflected = false;
 065   
 066      /**
 067       * Export reflection
 068       *
 069       * Required by the Reflector interface.
 070       *
 071       * @todo   What should this do?
 072       * @return void
 073       */
 074      public static function export()
 075      {
 076      }
 077   
 078      /**
 079       * @param  Reflector|string $commentOrReflector
 080       * @param  null|DocBlockTagManager $tagManager
 081       * @throws Exception\InvalidArgumentException
 082       * @return DocBlockReflection
 083       */
 084      public function __construct($commentOrReflector, DocBlockTagManager $tagManager = null)
 085      {
 086          if (!$tagManager) {
 087              $tagManager = new DocBlockTagManager();
 088              $tagManager->initializeDefaultTags();
 089          }
 090          $this->tagManager = $tagManager;
 091   
 092          if ($commentOrReflector instanceof Reflector) {
 093              $this->reflector = $commentOrReflector;
 094              if (!method_exists($commentOrReflector, 'getDocComment')) {
 095                  throw new Exception\InvalidArgumentException('Reflector must contain method "getDocComment"');
 096              }
 097              /* @var MethodReflection $commentOrReflector */
 098              $this->docComment = $commentOrReflector->getDocComment();
 099   
 100              // determine line numbers
 101              $lineCount       = substr_count($this->docComment, "\n");
 102              $this->startLine = $this->reflector->getStartLine() - $lineCount - 1;
 103              $this->endLine   = $this->reflector->getStartLine() - 1;
 104          } elseif (is_string($commentOrReflector)) {
 105              $this->docComment = $commentOrReflector;
 106          } else {
 107              throw new Exception\InvalidArgumentException(sprintf(
 108                  '%s must have a (string) DocComment or a Reflector in the constructor',
 109                  get_class($this)
 110              ));
 111          }
 112   
 113          if ($this->docComment == '') {
 114              throw new Exception\InvalidArgumentException('DocComment cannot be empty');
 115          }
 116   
 117          $this->reflect();
 118      }
 119   
 120      /**
 121       * Retrieve contents of DocBlock
 122       *
 123       * @return string
 124       */
 125      public function getContents()
 126      {
 127          $this->reflect();
 128   
 129          return $this->cleanDocComment;
 130      }
 131   
 132      /**
 133       * Get start line (position) of DocBlock
 134       *
 135       * @return int
 136       */
 137      public function getStartLine()
 138      {
 139          $this->reflect();
 140   
 141          return $this->startLine;
 142      }
 143   
 144      /**
 145       * Get last line (position) of DocBlock
 146       *
 147       * @return int
 148       */
 149      public function getEndLine()
 150      {
 151          $this->reflect();
 152   
 153          return $this->endLine;
 154      }
 155   
 156      /**
 157       * Get DocBlock short description
 158       *
 159       * @return string
 160       */
 161      public function getShortDescription()
 162      {
 163          $this->reflect();
 164   
 165          return $this->shortDescription;
 166      }
 167   
 168      /**
 169       * Get DocBlock long description
 170       *
 171       * @return string
 172       */
 173      public function getLongDescription()
 174      {
 175          $this->reflect();
 176   
 177          return $this->longDescription;
 178      }
 179   
 180      /**
 181       * Does the DocBlock contain the given annotation tag?
 182       *
 183       * @param  string $name
 184       * @return bool
 185       */
 186      public function hasTag($name)
 187      {
 188          $this->reflect();
 189          foreach ($this->tags as $tag) {
 190              if ($tag->getName() == $name) {
 191                  return true;
 192              }
 193          }
 194   
 195          return false;
 196      }
 197   
 198      /**
 199       * Retrieve the given DocBlock tag
 200       *
 201       * @param  string $name
 202       * @return DocBlockTagInterface|false
 203       */
 204      public function getTag($name)
 205      {
 206          $this->reflect();
 207          foreach ($this->tags as $tag) {
 208              if ($tag->getName() == $name) {
 209                  return $tag;
 210              }
 211          }
 212   
 213          return false;
 214      }
 215   
 216      /**
 217       * Get all DocBlock annotation tags
 218       *
 219       * @param  string $filter
 220       * @return DocBlockTagInterface[]
 221       */
 222      public function getTags($filter = null)
 223      {
 224          $this->reflect();
 225          if ($filter === null || !is_string($filter)) {
 226              return $this->tags;
 227          }
 228   
 229          $returnTags = array();
 230          foreach ($this->tags as $tag) {
 231              if ($tag->getName() == $filter) {
 232                  $returnTags[] = $tag;
 233              }
 234          }
 235   
 236          return $returnTags;
 237      }
 238   
 239      /**
 240       * Parse the DocBlock
 241       *
 242       * @return void
 243       */
 244      protected function reflect()
 245      {
 246          if ($this->isReflected) {
 247              return;
 248          }
 249   
 250          $docComment = preg_replace('#[ ]{0,1}\*/$#', '', $this->docComment);
 251   
 252          // create a clean docComment
 253          $this->cleanDocComment = preg_replace("#[ \t]*(?:/\*\*|\*/|\*)[ ]{0,1}(.*)?#", '$1', $docComment);
 254          $this->cleanDocComment = ltrim($this->cleanDocComment, "\r\n"); // @todo should be changed to remove first and last empty line
 255   
 256          $scanner                = new DocBlockScanner($docComment);
 257          $this->shortDescription = ltrim($scanner->getShortDescription());
 258          $this->longDescription  = ltrim($scanner->getLongDescription());
 259   
 260          foreach ($scanner->getTags() as $tag) {
 261              $this->tags[] = $this->tagManager->createTag(ltrim($tag['name'], '@'), ltrim($tag['value']));
 262          }
 263   
 264          $this->isReflected = true;
 265      }
 266   
 267      /**
 268       * @return string
 269       */
 270      public function toString()
 271      {
 272          $str = "DocBlock [ /* DocBlock */ ] {" . PHP_EOL . PHP_EOL;
 273          $str .= "  - Tags [" . count($this->tags) . "] {" . PHP_EOL;
 274   
 275          foreach ($this->tags as $tag) {
 276              $str .= "    " . $tag;
 277          }
 278   
 279          $str .= "  }" . PHP_EOL;
 280          $str .= "}" . PHP_EOL;
 281   
 282          return $str;
 283      }
 284   
 285      /**
 286       * Serialize to string
 287       *
 288       * Required by the Reflector interface
 289       *
 290       * @return string
 291       */
 292      public function __toString()
 293      {
 294          return $this->toString();
 295      }
 296  }
 297