‪TYPO3CMS  9.5
DocCommentParser.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
22 {
26  protected static ‪$ignoredTags = ['package', 'subpackage', 'license', 'copyright', 'author', 'version', 'const'];
27 
31  protected ‪$description = '';
32 
36  protected ‪$tags = [];
37 
41  private ‪$useIgnoredTags;
42 
46  public function ‪__construct(‪$useIgnoredTags = false)
47  {
48  $this->useIgnoredTags = ‪$useIgnoredTags;
49  }
50 
58  public function ‪parseDocComment($docComment)
59  {
60  $this->description = '';
61  $this->tags = [];
62  $lines = explode(LF, $docComment);
63  foreach ($lines as $line) {
64  if ($line !== '' && strpos($line, '@') !== false) {
65  $this->‪parseTag(substr($line, strpos($line, '@')));
66  } elseif (empty($this->tags)) {
67  $this->description .= preg_replace('#\\s*/?[*/]*(.*)$#', '$1', $line) . LF;
68  }
69  }
70  $this->description = trim($this->description);
71  }
72 
78  public function ‪getTagsValues()
79  {
80  return ‪$this->tags;
81  }
82 
92  public function ‪getTagValues($tagName)
93  {
94  if (!$this->‪isTaggedWith($tagName)) {
95  throw new \RuntimeException('Tag "' . $tagName . '" does not exist.', 1169128255);
96  }
97  return $this->tags[$tagName];
98  }
99 
106  public function ‪isTaggedWith($tagName)
107  {
108  return isset($this->tags[$tagName]);
109  }
110 
116  public function ‪getDescription()
117  {
118  return ‪$this->description;
119  }
120 
127  protected function ‪parseTag($line)
128  {
129  $tagAndValue = preg_split('/\\s/', $line, 2);
130  $tag = substr($tagAndValue[0], 1);
131 
132  if ($this->useIgnoredTags && in_array($tag, static::$ignoredTags, true)) {
133  return;
134  }
135 
136  if (count($tagAndValue) > 1) {
137  $this->tags[$tag][] = trim($tagAndValue[1]);
138  } else {
139  $this->tags[$tag] = [];
140  }
141  }
142 }
‪TYPO3\CMS\Extbase\Reflection\DocCommentParser\$useIgnoredTags
‪bool $useIgnoredTags
Definition: DocCommentParser.php:37
‪TYPO3\CMS\Extbase\Reflection\DocCommentParser\getTagsValues
‪array getTagsValues()
Definition: DocCommentParser.php:74
‪TYPO3\CMS\Extbase\Reflection\DocCommentParser\isTaggedWith
‪bool isTaggedWith($tagName)
Definition: DocCommentParser.php:102
‪TYPO3\CMS\Extbase\Reflection\DocCommentParser\getTagValues
‪array getTagValues($tagName)
Definition: DocCommentParser.php:88
‪TYPO3\CMS\Extbase\Reflection\DocCommentParser\$ignoredTags
‪static array $ignoredTags
Definition: DocCommentParser.php:25
‪TYPO3\CMS\Extbase\Reflection\DocCommentParser\$description
‪string $description
Definition: DocCommentParser.php:29
‪TYPO3\CMS\Extbase\Reflection\DocCommentParser
Definition: DocCommentParser.php:22
‪TYPO3\CMS\Extbase\Reflection\DocCommentParser\parseDocComment
‪parseDocComment($docComment)
Definition: DocCommentParser.php:54
‪TYPO3\CMS\Extbase\Reflection
Definition: ClassSchema.php:2
‪TYPO3\CMS\Extbase\Reflection\DocCommentParser\__construct
‪__construct($useIgnoredTags=false)
Definition: DocCommentParser.php:42
‪TYPO3\CMS\Extbase\Reflection\DocCommentParser\$tags
‪array $tags
Definition: DocCommentParser.php:33
‪TYPO3\CMS\Extbase\Reflection\DocCommentParser\parseTag
‪parseTag($line)
Definition: DocCommentParser.php:123
‪TYPO3\CMS\Extbase\Reflection\DocCommentParser\getDescription
‪string getDescription()
Definition: DocCommentParser.php:112