TYPO3 CMS  TYPO3_8-7
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 
21 {
25  protected $description = '';
26 
30  protected $tags = [];
31 
39  public function parseDocComment($docComment)
40  {
41  $this->description = '';
42  $this->tags = [];
43  $lines = explode(LF, $docComment);
44  foreach ($lines as $line) {
45  if ($line !== '' && strpos($line, '@') !== false) {
46  $this->parseTag(substr($line, strpos($line, '@')));
47  } elseif (empty($this->tags)) {
48  $this->description .= preg_replace('#\\s*/?[*/]*(.*)$#', '$1', $line) . LF;
49  }
50  }
51  $this->description = trim($this->description);
52  }
53 
59  public function getTagsValues()
60  {
61  return $this->tags;
62  }
63 
73  public function getTagValues($tagName)
74  {
75  if (!$this->isTaggedWith($tagName)) {
76  throw new \RuntimeException('Tag "' . $tagName . '" does not exist.', 1169128255);
77  }
78  return $this->tags[$tagName];
79  }
80 
87  public function isTaggedWith($tagName)
88  {
89  return isset($this->tags[$tagName]);
90  }
91 
97  public function getDescription()
98  {
99  return $this->description;
100  }
101 
108  protected function parseTag($line)
109  {
110  $tagAndValue = preg_split('/\\s/', $line, 2);
111  $tag = substr($tagAndValue[0], 1);
112  if (count($tagAndValue) > 1) {
113  $this->tags[$tag][] = trim($tagAndValue[1]);
114  } else {
115  $this->tags[$tag] = [];
116  }
117  }
118 }