TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
DocCommentParser.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Extbase\Reflection;
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 
40  public function parseDocComment($docComment)
41  {
42  $this->description = '';
43  $this->tags = [];
44  $lines = explode(LF, $docComment);
45  foreach ($lines as $line) {
46  if ($line !== '' && strpos($line, '@') !== false) {
47  $this->parseTag(substr($line, strpos($line, '@')));
48  } elseif (empty($this->tags)) {
49  $this->description .= preg_replace('#\\s*/?[*/]*(.*)$#', '$1', $line) . LF;
50  }
51  }
52  $this->description = trim($this->description);
53  }
54 
60  public function getTagsValues()
61  {
62  return $this->tags;
63  }
64 
74  public function getTagValues($tagName)
75  {
76  if (!$this->isTaggedWith($tagName)) {
77  throw new \RuntimeException('Tag "' . $tagName . '" does not exist.', 1169128255);
78  }
79  return $this->tags[$tagName];
80  }
81 
88  public function isTaggedWith($tagName)
89  {
90  return isset($this->tags[$tagName]);
91  }
92 
98  public function getDescription()
99  {
100  return $this->description;
101  }
102 
110  protected function parseTag($line)
111  {
112  $tagAndValue = preg_split('/\\s/', $line, 2);
113  $tag = substr($tagAndValue[0], 1);
114  if (count($tagAndValue) > 1) {
115  $this->tags[$tag][] = trim($tagAndValue[1]);
116  } else {
117  $this->tags[$tag] = [];
118  }
119  }
120 }