From c501553216e79c72fcd9b6633b5a32fc1e92ceed Mon Sep 17 00:00:00 2001 From: Vasil Rangelov Date: Sat, 22 Sep 2012 05:41:10 +0300 Subject: [PATCH 1/5] Added parsed inline tags. --- .../Reflection/DocBlock/LongDescription.php | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/phpDocumentor/Reflection/DocBlock/LongDescription.php b/src/phpDocumentor/Reflection/DocBlock/LongDescription.php index df45fe3..9a8e5d6 100644 --- a/src/phpDocumentor/Reflection/DocBlock/LongDescription.php +++ b/src/phpDocumentor/Reflection/DocBlock/LongDescription.php @@ -26,6 +26,9 @@ class LongDescription implements \Reflector /** @var \phpDocumentor\Reflection\DocBlock\Tags[] */ protected $tags = array(); + + /** @var array The contents, as an array of strings and Tag objects. */ + protected $parsedContents = array(); /** * Parses the string for inline tags and if the Markdown class is included; @@ -35,13 +38,13 @@ class LongDescription implements \Reflector */ public function __construct($content) { - if (preg_match('/\{\@(.+?)\}/u', $content, $matches)) { - array_shift($matches); - foreach ($matches as $tag) { - $this->tags[] = Tag::createInstance('@' . $tag); - } + $this->parsedContents = preg_split('/{\@(.+?)\}/uS', $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->contents = trim($content); } @@ -54,6 +57,11 @@ class LongDescription implements \Reflector { return $this->contents; } + + public function getParsedContents() + { + return $this->parsedContents; + } /** * Return a formatted variant of the Long Description using MarkDown. From ddc3005eea17cc9eac29bf943979c6d932b3d65e Mon Sep 17 00:00:00 2001 From: Vasil Rangelov Date: Sat, 22 Sep 2012 05:56:37 +0300 Subject: [PATCH 2/5] Added doc block to getParsedContents(). --- src/phpDocumentor/Reflection/DocBlock/LongDescription.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/phpDocumentor/Reflection/DocBlock/LongDescription.php b/src/phpDocumentor/Reflection/DocBlock/LongDescription.php index 9a8e5d6..14aa652 100644 --- a/src/phpDocumentor/Reflection/DocBlock/LongDescription.php +++ b/src/phpDocumentor/Reflection/DocBlock/LongDescription.php @@ -58,6 +58,12 @@ class LongDescription implements \Reflector return $this->contents; } + /* + * 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() { return $this->parsedContents; From a2bf8995dc3bff073832a309540090b5ca1c96ce Mon Sep 17 00:00:00 2001 From: Vasil Rangelov Date: Wed, 26 Sep 2012 16:27:32 +0300 Subject: [PATCH 3/5] 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 From f001c3cd92c2e04baf3ebf90ffe6ab30667d4e3e Mon Sep 17 00:00:00 2001 From: Vasil Rangelov Date: Wed, 17 Oct 2012 17:33:52 +0300 Subject: [PATCH 4/5] Removed LongDescription::getTags() and made parsing to occur only the first time it's requested. --- .../Reflection/DocBlock/LongDescription.php | 37 +++++++------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/src/phpDocumentor/Reflection/DocBlock/LongDescription.php b/src/phpDocumentor/Reflection/DocBlock/LongDescription.php index b508b8d..455a765 100644 --- a/src/phpDocumentor/Reflection/DocBlock/LongDescription.php +++ b/src/phpDocumentor/Reflection/DocBlock/LongDescription.php @@ -23,12 +23,9 @@ class LongDescription implements \Reflector { /** @var string */ protected $contents = ''; - - /** @var \phpDocumentor\Reflection\DocBlock\Tags[] */ - protected $tags = array(); /** @var array The contents, as an array of strings and Tag objects. */ - protected $parsedContents = array(); + protected $parsedContents = null; /** * Parses the string for inline tags and if the Markdown class is included; @@ -38,16 +35,7 @@ class LongDescription implements \Reflector */ public function __construct($content) { - $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->contents = trim($content); } /** @@ -68,6 +56,17 @@ class LongDescription implements \Reflector */ public function getParsedContents() { + if (null === $this->parsedContents) { + $this->parsedContents = preg_split( + '/\{(\@.*)\}/uS', $this->contents, + null, PREG_SPLIT_DELIM_CAPTURE + ); + for ($i=1, $l = count($this->parsedContents); $i<$l; $i += 2) { + $this->parsedContents[$i] = Tag::createInstance( + $this->parsedContents[$i] + ); + } + } return $this->parsedContents; } @@ -102,16 +101,6 @@ class LongDescription implements \Reflector return trim($result); } - /** - * Returns a list of tags mentioned in the text. - * - * @return \phpDocumentor\Reflection\DocBlock\Tags[] - */ - public function getTags() - { - return $this->tags; - } - /** * Builds a string representation of this object. * From b028b5eb44dcce8ccc227c9fd65f980deb75411b Mon Sep 17 00:00:00 2001 From: Vasil Rangelov Date: Wed, 31 Oct 2012 11:28:53 +0200 Subject: [PATCH 5/5] Restored the greedy-ness inversion. --- src/phpDocumentor/Reflection/DocBlock/LongDescription.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/phpDocumentor/Reflection/DocBlock/LongDescription.php b/src/phpDocumentor/Reflection/DocBlock/LongDescription.php index 455a765..a99bd81 100644 --- a/src/phpDocumentor/Reflection/DocBlock/LongDescription.php +++ b/src/phpDocumentor/Reflection/DocBlock/LongDescription.php @@ -58,7 +58,7 @@ class LongDescription implements \Reflector { if (null === $this->parsedContents) { $this->parsedContents = preg_split( - '/\{(\@.*)\}/uS', $this->contents, + '/\{(\@.*?)\}/uS', $this->contents, null, PREG_SPLIT_DELIM_CAPTURE ); for ($i=1, $l = count($this->parsedContents); $i<$l; $i += 2) {