Skip to content

Commit 5236694

Browse files
committed
Merge branch 'patch-2' of https://github.com/boenrobot/ReflectionDocBlock into boenrobot-patch-2
Conflicts: src/phpDocumentor/Reflection/DocBlock/LongDescription.php
2 parents 5941846 + ce57e54 commit 5236694

File tree

2 files changed

+47
-21
lines changed

2 files changed

+47
-21
lines changed

src/phpDocumentor/Reflection/DocBlock/LongDescription.php

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ class LongDescription implements \Reflector
2424
/** @var string */
2525
protected $contents = '';
2626

27-
/** @var Tag[] */
27+
/** @var array The contents, as an array of strings and Tag objects. */
28+
protected $parsedContents = null;
29+
30+
/** @var \phpDocumentor\Reflection\DocBlock\Tags[] */
2831
protected $tags = array();
2932

3033
/**
@@ -35,13 +38,6 @@ class LongDescription implements \Reflector
3538
*/
3639
public function __construct($content)
3740
{
38-
if (preg_match('/\{\@(.+?)\}/u', $content, $matches)) {
39-
array_shift($matches);
40-
foreach ($matches as $tag) {
41-
$this->tags[] = Tag::createInstance('@' . $tag);
42-
}
43-
}
44-
4541
$this->contents = trim($content);
4642
}
4743

@@ -55,6 +51,28 @@ public function getContents()
5551
return $this->contents;
5652
}
5753

54+
/*
55+
* Returns the parsed text of this description.
56+
*
57+
* @return array An array of strings and tag objects, in the order they
58+
* occur within the description.
59+
*/
60+
public function getParsedContents()
61+
{
62+
if (null === $this->parsedContents) {
63+
$this->parsedContents = preg_split(
64+
'/\{(\@.*?)\}/uS', $this->contents,
65+
null, PREG_SPLIT_DELIM_CAPTURE
66+
);
67+
for ($i=1, $l = count($this->parsedContents); $i<$l; $i += 2) {
68+
$this->parsedContents[$i] = Tag::createInstance(
69+
$this->parsedContents[$i]
70+
);
71+
}
72+
}
73+
return $this->parsedContents;
74+
}
75+
5876
/**
5977
* Return a formatted variant of the Long Description using MarkDown.
6078
*
@@ -86,16 +104,6 @@ public function getFormattedContents()
86104
return trim($result);
87105
}
88106

89-
/**
90-
* Returns a list of tags mentioned in the text.
91-
*
92-
* @return \phpDocumentor\Reflection\DocBlock\Tags[]
93-
*/
94-
public function getTags()
95-
{
96-
return $this->tags;
97-
}
98-
99107
/**
100108
* Builds a string representation of this object.
101109
*

src/phpDocumentor/Reflection/DocBlock/Tag.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,16 @@ class Tag implements \Reflector
2424
/** @var string Name of the tag */
2525
protected $tag = '';
2626

27-
/** @var string content of the tag */
27+
/** @var string Content of the tag */
2828
protected $content = '';
2929

30-
/** @var string description of the content of this tag */
30+
/** @var string Description of the content of this tag */
3131
protected $description = '';
32+
33+
/** @var array The description, as an array of strings and Tag objects. */
34+
protected $parsedDescription = null;
3235

33-
/** @var int line number of the tag */
36+
/** @var int Line number of the tag */
3437
protected $line_number = 0;
3538

3639
/** @var \phpDocumentor\Reflection\DocBlock docblock class */
@@ -108,6 +111,21 @@ public function getDescription()
108111
{
109112
return $this->description;
110113
}
114+
115+
/*
116+
* Returns the parsed text of this description.
117+
*
118+
* @return array An array of strings and tag objects, in the order they
119+
* occur within the description.
120+
*/
121+
public function getParsedDescription()
122+
{
123+
if (null === $this->parsedDescription) {
124+
$description = new LongDescription($this->description);
125+
$this->parsedDescription = $description->getParsedContents();
126+
}
127+
return $this->parsedDescription;
128+
}
111129

112130
/**
113131
* Set the tag line number

0 commit comments

Comments
 (0)