/** * Returns the parsed text of this description. * * @return array An array of strings and tag objects, in the order they * occur within the description. */ public function getParsedContents() { if (null === $this->parsedContents) { $this->parsedContents = preg_split('/\\{ # "{@}" is not a valid inline tag. This ensures that # we do not treat it as one, but treat it literally. (?!@\\}) # We want to capture the whole tag line, but without the # inline tag delimiters. (\\@ # Match everything up to the next delimiter. [^{}]* # Nested inline tag content should not be captured, or # it will appear in the result separately. (?: # Match nested inline tags. (?: # Because we did not catch the tag delimiters # earlier, we must be explicit with them here. # Notice that this also matches "{}", as a way # to later introduce it as an escape sequence. \\{(?1)?\\} | # Make sure we match hanging "{". \\{ ) # Match content after the nested inline tag. [^{}]* )* # If there are more inline tags, match them as well. # We use "*" since there may not be any nested inline # tags. ) \\}/Sux', $this->contents, null, PREG_SPLIT_DELIM_CAPTURE); $count = count($this->parsedContents); for ($i = 1; $i < $count; $i += 2) { $this->parsedContents[$i] = Tag::createInstance($this->parsedContents[$i], $this->docblock); } //In order to allow "literal" inline tags, the otherwise invalid //sequence "{@}" is changed to "@", and "{}" is changed to "}". //See unit tests for examples. for ($i = 0; $i < $count; $i += 2) { $this->parsedContents[$i] = str_replace(array('{@}', '{}'), array('@', '}'), $this->parsedContents[$i]); } } return $this->parsedContents; }
/** * @covers \phpDocumentor\Reflection\DocBlock\Tag::registerTagHandler * * @return void */ public function testIncompatibleTagHandlerRegistration() { $currentHandler = __NAMESPACE__ . '\\Tag\\VarTag'; $tagPreReg = Tag::createInstance('@var mixed'); $this->assertInstanceOf($currentHandler, $tagPreReg); $this->assertInstanceOf(__NAMESPACE__ . '\\Tag', $tagPreReg); $this->assertFalse(Tag::registerTagHandler('var', __NAMESPACE__ . '\\TagTest')); $tagPostReg = Tag::createInstance('@var mixed'); $this->assertInstanceOf($currentHandler, $tagPostReg); $this->assertInstanceOf(__NAMESPACE__ . '\\Tag', $tagPostReg); }
/** * Creates the tag objects. * * @param string $tags Tag block to parse. * * @return void */ protected function parseTags($tags) { $result = array(); $tags = trim($tags); if ('' !== $tags) { if ('@' !== $tags[0]) { throw new \LogicException('A tag block started with text instead of an actual tag,' . ' this makes the tag block invalid: ' . $tags); } foreach (explode("\n", $tags) as $tag_line) { if (isset($tag_line[0]) && $tag_line[0] === '@') { $result[] = $tag_line; } else { $result[count($result) - 1] .= "\n" . $tag_line; } } // create proper Tag objects foreach ($result as $key => $tag_line) { $result[$key] = Tag::createInstance(trim($tag_line), $this); } } $this->tags = $result; }