From a2bf8995dc3bff073832a309540090b5ca1c96ce Mon Sep 17 00:00:00 2001 From: Vasil Rangelov Date: Wed, 26 Sep 2012 16:27:32 +0300 Subject: [PATCH] Added Tag::getParsedDescription(); Minor performance tweak at LongDescription. --- .../Reflection/DocBlock/LongDescription.php | 10 ++++---- src/phpDocumentor/Reflection/DocBlock/Tag.php | 24 ++++++++++++++++--- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/phpDocumentor/Reflection/DocBlock/LongDescription.php b/src/phpDocumentor/Reflection/DocBlock/LongDescription.php index 14aa652..b508b8d 100644 --- a/src/phpDocumentor/Reflection/DocBlock/LongDescription.php +++ b/src/phpDocumentor/Reflection/DocBlock/LongDescription.php @@ -38,14 +38,16 @@ class LongDescription implements \Reflector */ public function __construct($content) { - $this->parsedContents = preg_split('/{\@(.+?)\}/uS', $content, null, PREG_SPLIT_DELIM_CAPTURE); + $this->parsedContents = preg_split( + '/\{(\@.*)\}/uS', + $this->contents = trim($content), + null, PREG_SPLIT_DELIM_CAPTURE + ); for ($i=1, $l = count($this->parsedContents); $i<$l; $i += 2) { $this->parsedContents[$i] = $this->tags[] = Tag::createInstance( - '@' . $this->parsedContents[$i] + $this->parsedContents[$i] ); } - - $this->contents = trim($content); } /** diff --git a/src/phpDocumentor/Reflection/DocBlock/Tag.php b/src/phpDocumentor/Reflection/DocBlock/Tag.php index 89bf708..4ad3620 100644 --- a/src/phpDocumentor/Reflection/DocBlock/Tag.php +++ b/src/phpDocumentor/Reflection/DocBlock/Tag.php @@ -24,13 +24,16 @@ class Tag implements \Reflector /** @var string Name of the tag */ protected $tag = ''; - /** @var string content of the tag */ + /** @var string Content of the tag */ protected $content = ''; - /** @var string description of the content of this tag */ + /** @var string Description of the content of this tag */ protected $description = ''; + + /** @var array The description, as an array of strings and Tag objects. */ + protected $parsedDescription = null; - /** @var int line number of the tag */ + /** @var int Line number of the tag */ protected $line_number = 0; /** @var \phpDocumentor\Reflection\DocBlock docblock class */ @@ -108,6 +111,21 @@ class Tag implements \Reflector { return $this->description; } + + /* + * 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 getParsedDescription() + { + if (null === $this->parsedDescription) { + $description = new LongDescription($this->description); + $this->parsedDescription = $description->getParsedContents(); + } + return $this->parsedDescription; + } /** * Set the tag line number