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

DocBlockGenerator.php

Zuletzt modifiziert: 09.10.2024, 12:57 - Dateigröße: 6.92 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\Generator;
 011   
 012  use Zend\Code\Generator\DocBlock\Tag;
 013  use Zend\Code\Generator\DocBlock\Tag\TagInterface;
 014  use Zend\Code\Generator\DocBlock\TagManager;
 015  use Zend\Code\Reflection\DocBlockReflection;
 016   
 017  class DocBlockGenerator extends AbstractGenerator
 018  {
 019      /**
 020       * @var string
 021       */
 022      protected $shortDescription = null;
 023   
 024      /**
 025       * @var string
 026       */
 027      protected $longDescription = null;
 028   
 029      /**
 030       * @var array
 031       */
 032      protected $tags = array();
 033   
 034      /**
 035       * @var string
 036       */
 037      protected $indentation = '';
 038   
 039      /**
 040       * @var bool
 041       */
 042      protected $wordwrap = true;
 043   
 044      protected static $tagManager;
 045   
 046      /**
 047       * Build a DocBlock generator object from a reflection object
 048       *
 049       * @param  DocBlockReflection $reflectionDocBlock
 050       * @return DocBlockGenerator
 051       */
 052      public static function fromReflection(DocBlockReflection $reflectionDocBlock)
 053      {
 054          $docBlock = new static();
 055   
 056          $docBlock->setSourceContent($reflectionDocBlock->getContents());
 057          $docBlock->setSourceDirty(false);
 058   
 059          $docBlock->setShortDescription($reflectionDocBlock->getShortDescription());
 060          $docBlock->setLongDescription($reflectionDocBlock->getLongDescription());
 061   
 062          foreach ($reflectionDocBlock->getTags() as $tag) {
 063              $docBlock->setTag(self::getTagManager()->createTagFromReflection($tag));
 064          }
 065   
 066          return $docBlock;
 067      }
 068   
 069      /**
 070       * Generate from array
 071       *
 072       * @configkey shortdescription string The short description for this doc block
 073       * @configkey longdescription  string The long description for this doc block
 074       * @configkey tags             array
 075       *
 076       * @throws Exception\InvalidArgumentException
 077       * @param  array $array
 078       * @return DocBlockGenerator
 079       */
 080      public static function fromArray(array $array)
 081      {
 082          $docBlock = new static();
 083   
 084          foreach ($array as $name => $value) {
 085              // normalize key
 086              switch (strtolower(str_replace(array('.', '-', '_'), '', $name))) {
 087                  case 'shortdescription':
 088                      $docBlock->setShortDescription($value);
 089                      break;
 090                  case 'longdescription':
 091                      $docBlock->setLongDescription($value);
 092                      break;
 093                  case 'tags':
 094                      $docBlock->setTags($value);
 095                      break;
 096              }
 097          }
 098   
 099          return $docBlock;
 100      }
 101   
 102      protected static function getTagManager()
 103      {
 104          if (!isset(static::$tagManager)) {
 105              static::$tagManager = new TagManager();
 106              static::$tagManager->initializeDefaultTags();
 107          }
 108          return static::$tagManager;
 109      }
 110   
 111      /**
 112       * @param  string $shortDescription
 113       * @param  string $longDescription
 114       * @param  array $tags
 115       */
 116      public function __construct($shortDescription = null, $longDescription = null, array $tags = array())
 117      {
 118          if ($shortDescription) {
 119              $this->setShortDescription($shortDescription);
 120          }
 121          if ($longDescription) {
 122              $this->setLongDescription($longDescription);
 123          }
 124          if (is_array($tags) && $tags) {
 125              $this->setTags($tags);
 126          }
 127      }
 128   
 129      /**
 130       * @param  string $shortDescription
 131       * @return DocBlockGenerator
 132       */
 133      public function setShortDescription($shortDescription)
 134      {
 135          $this->shortDescription = $shortDescription;
 136          return $this;
 137      }
 138   
 139      /**
 140       * @return string
 141       */
 142      public function getShortDescription()
 143      {
 144          return $this->shortDescription;
 145      }
 146   
 147      /**
 148       * @param  string $longDescription
 149       * @return DocBlockGenerator
 150       */
 151      public function setLongDescription($longDescription)
 152      {
 153          $this->longDescription = $longDescription;
 154          return $this;
 155      }
 156   
 157      /**
 158       * @return string
 159       */
 160      public function getLongDescription()
 161      {
 162          return $this->longDescription;
 163      }
 164   
 165      /**
 166       * @param  array $tags
 167       * @return DocBlockGenerator
 168       */
 169      public function setTags(array $tags)
 170      {
 171          foreach ($tags as $tag) {
 172              $this->setTag($tag);
 173          }
 174   
 175          return $this;
 176      }
 177   
 178      /**
 179       * @param array|TagInterface $tag
 180       * @throws Exception\InvalidArgumentException
 181       * @return DocBlockGenerator
 182       */
 183      public function setTag($tag)
 184      {
 185          if (is_array($tag)) {
 186              // use deprecated Tag class for backward compatiblity to old array-keys
 187              $genericTag = new Tag();
 188              $genericTag->setOptions($tag);
 189              $tag = $genericTag;
 190          } elseif (!$tag instanceof TagInterface) {
 191              throw new Exception\InvalidArgumentException(sprintf(
 192                  '%s expects either an array of method options or an instance of %s\DocBlock\Tag\TagInterface',
 193                  __METHOD__,
 194                  __NAMESPACE__
 195              ));
 196          }
 197   
 198          $this->tags[] = $tag;
 199          return $this;
 200      }
 201   
 202      /**
 203       * @return TagInterface[]
 204       */
 205      public function getTags()
 206      {
 207          return $this->tags;
 208      }
 209   
 210      /**
 211       * @param bool $value
 212       * @return DocBlockGenerator
 213       */
 214      public function setWordWrap($value)
 215      {
 216          $this->wordwrap = (bool) $value;
 217          return $this;
 218      }
 219   
 220      /**
 221       * @return bool
 222       */
 223      public function getWordWrap()
 224      {
 225          return $this->wordwrap;
 226      }
 227   
 228      /**
 229       * @return string
 230       */
 231      public function generate()
 232      {
 233          if (!$this->isSourceDirty()) {
 234              return $this->docCommentize(trim($this->getSourceContent()));
 235          }
 236   
 237          $output = '';
 238          if (null !== ($sd = $this->getShortDescription())) {
 239              $output .= $sd . self::LINE_FEED . self::LINE_FEED;
 240          }
 241          if (null !== ($ld = $this->getLongDescription())) {
 242              $output .= $ld . self::LINE_FEED . self::LINE_FEED;
 243          }
 244   
 245          /* @var $tag GeneratorInterface */
 246          foreach ($this->getTags() as $tag) {
 247              $output .= $tag->generate() . self::LINE_FEED;
 248          }
 249   
 250          return $this->docCommentize(trim($output));
 251      }
 252   
 253      /**
 254       * @param  string $content
 255       * @return string
 256       */
 257      protected function docCommentize($content)
 258      {
 259          $indent  = $this->getIndentation();
 260          $output  = $indent . '/**' . self::LINE_FEED;
 261          $content = $this->getWordWrap() == true ? wordwrap($content, 80, self::LINE_FEED) : $content;
 262          $lines   = explode(self::LINE_FEED, $content);
 263          foreach ($lines as $line) {
 264              $output .= $indent . ' *';
 265              if ($line) {
 266                  $output .= " $line";
 267              }
 268              $output .= self::LINE_FEED;
 269          }
 270          $output .= $indent . ' */' . self::LINE_FEED;
 271   
 272          return $output;
 273      }
 274  }
 275