TYPO3 CMS  TYPO3_6-2
DocCommentParser.php
Go to the documentation of this file.
1 <?php
3 
20 
24  protected $description = '';
25 
29  protected $tags = array();
30 
39  public function parseDocComment($docComment) {
40  $this->description = '';
41  $this->tags = array();
42  $lines = explode(chr(10), $docComment);
43  foreach ($lines as $line) {
44  if (strlen($line) > 0 && strpos($line, '@') !== FALSE) {
45  $this->parseTag(substr($line, strpos($line, '@')));
46  } elseif (count($this->tags) === 0) {
47  $this->description .= preg_replace('/\\s*\\/?[\\\\*]*(.*)$/', '$1', $line) . chr(10);
48  }
49  }
50  $this->description = trim($this->description);
51  }
52 
58  public function getTagsValues() {
59  return $this->tags;
60  }
61 
71  public function getTagValues($tagName) {
72  if (!$this->isTaggedWith($tagName)) {
73  throw new \RuntimeException('Tag "' . $tagName . '" does not exist.', 1169128255);
74  }
75  return $this->tags[$tagName];
76  }
77 
84  public function isTaggedWith($tagName) {
85  return isset($this->tags[$tagName]);
86  }
87 
93  public function getDescription() {
94  return $this->description;
95  }
96 
104  protected function parseTag($line) {
105  $tagAndValue = preg_split('/\\s/', $line, 2);
106  $tag = substr($tagAndValue[0], 1);
107  if (count($tagAndValue) > 1) {
108  $this->tags[$tag][] = trim($tagAndValue[1]);
109  } else {
110  $this->tags[$tag] = array();
111  }
112  }
113 }