Skip to content

Commit 99054d3

Browse files
committed
Introduced Context and Location, and adapted Collection and ReturnTag accordingly.
1 parent 9da4a65 commit 99054d3

File tree

17 files changed

+400
-245
lines changed

17 files changed

+400
-245
lines changed

src/phpDocumentor/Reflection/DocBlock.php

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
namespace phpDocumentor\Reflection;
1414

15+
use phpDocumentor\Reflection\DocBlock\Context;
16+
use phpDocumentor\Reflection\DocBlock\Location;
17+
1518
/**
1619
* Parses the DocBlock for any structure.
1720
*
@@ -36,11 +39,11 @@ class DocBlock implements \Reflector
3639
*/
3740
protected $tags = array();
3841

39-
/** @var string the current namespace */
40-
protected $namespace = '\\';
42+
/** @var Context Information about the context of this DocBlock. */
43+
protected $context = null;
4144

42-
/** @var array List of namespace aliases => Fully Qualified Namespace */
43-
protected $namespace_aliases = array();
45+
/** @var Location Information about the location of this DocBlock. */
46+
protected $location = null;
4447

4548
/**
4649
* Parses the given docblock and populates the member fields.
@@ -49,21 +52,20 @@ class DocBlock implements \Reflector
4952
* current namespace and aliases. This information is used by some tags
5053
* (e.g. @return, @param, etc.) to turn a relative Type into a FQCN.
5154
*
52-
* @param \Reflector|string $docblock A docblock comment (including
55+
* @param \Reflector|string $docblock A docblock comment (including
5356
* asterisks) or reflector supporting the getDocComment method.
54-
* @param string $namespace The namespace where this
55-
* DocBlock resides in; defaults to `\`.
56-
* @param array $namespace_aliases A list of namespace aliases
57-
* as provided by the `use` keyword; the key of the array is the alias
58-
* name or last part of the alias array if no alias name is provided.
57+
* @param Context $context The context in which the DocBlock
58+
* occurs.
59+
* @param Location $location The location within the file that this
60+
* DocBlock occurs in.
5961
*
6062
* @throws \InvalidArgumentException if the given argument does not have the
6163
* getDocComment method.
6264
*/
6365
public function __construct(
6466
$docblock,
65-
$namespace = '\\',
66-
array $namespace_aliases = array()
67+
Context $context = null,
68+
Location $location = null
6769
) {
6870
if (is_object($docblock)) {
6971
if (!method_exists($docblock, 'getDocComment')) {
@@ -83,8 +85,8 @@ public function __construct(
8385
$this->long_description = new DocBlock\Description($long, $this);
8486
$this->parseTags($tags);
8587

86-
$this->namespace = $namespace;
87-
$this->namespace_aliases = $namespace_aliases;
88+
$this->context = $context;
89+
$this->location = $location;
8890
}
8991

9092
/**
@@ -246,6 +248,26 @@ public function getLongDescription()
246248
return $this->long_description;
247249
}
248250

251+
/**
252+
* Returns the current context.
253+
*
254+
* @return Context
255+
*/
256+
public function getContext()
257+
{
258+
return $this->context;
259+
}
260+
261+
/**
262+
* Returns the current location.
263+
*
264+
* @return Location
265+
*/
266+
public function getLocation()
267+
{
268+
return $this->location;
269+
}
270+
249271
/**
250272
* Returns the tags for this DocBlock.
251273
*
@@ -324,20 +346,4 @@ public function __toString()
324346
{
325347
return 'Not yet implemented';
326348
}
327-
328-
/**
329-
* @return string The namespace where this DocBlock resides in.
330-
*/
331-
public function getNamespace()
332-
{
333-
return $this->namespace;
334-
}
335-
336-
/**
337-
* @return array List of namespace aliases => Fully Qualified Namespace.
338-
*/
339-
public function getNamespaceAliases()
340-
{
341-
return $this->namespace_aliases;
342-
}
343349
}
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
<?php
2+
/**
3+
* phpDocumentor
4+
*
5+
* PHP Version 5.3
6+
*
7+
* @author Vasil Rangelov <[email protected]>
8+
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
9+
* @license http://www.opensource.org/licenses/mit-license.php MIT
10+
* @link http://phpdoc.org
11+
*/
12+
13+
namespace phpDocumentor\Reflection\DocBlock;
14+
15+
/**
16+
* The context in which a DocBlock occurs.
17+
*
18+
* @author Vasil Rangelov <[email protected]>
19+
* @license http://www.opensource.org/licenses/mit-license.php MIT
20+
* @link http://phpdoc.org
21+
*/
22+
class Context
23+
{
24+
/** @var string The current namespace. */
25+
protected $namespace = '';
26+
27+
/** @var array List of namespace aliases => Fully Qualified Namespace. */
28+
protected $namespace_aliases = array();
29+
30+
/** @var string Name of the structural element, within the namespace. */
31+
protected $lsen = '';
32+
33+
/**
34+
*
35+
* @param string $namespace The namespace where this DocBlock
36+
* resides in.
37+
* @param array $namespace_aliases List of namespace aliases => Fully
38+
* Qualified Namespace.
39+
* @param string $lsen Name of the structural element, within
40+
* the namespace.
41+
*/
42+
public function __construct(
43+
$namespace = '',
44+
array $namespace_aliases = array(),
45+
$lsen = ''
46+
) {
47+
if (!empty($namespace)) {
48+
$this->setNamespace($namespace);
49+
}
50+
$this->setNamespaceAliases($namespace_aliases);
51+
$this->setLSEN($lsen);
52+
}
53+
54+
/**
55+
* @return string The namespace where this DocBlock resides in.
56+
*/
57+
public function getNamespace()
58+
{
59+
return $this->namespace;
60+
}
61+
62+
/**
63+
* @return array List of namespace aliases => Fully Qualified Namespace.
64+
*/
65+
public function getNamespaceAliases()
66+
{
67+
return $this->namespace_aliases;
68+
}
69+
70+
/**
71+
* Returns the Local Structural Element Name.
72+
*
73+
* @return string Name of the structural element, within the namespace.
74+
*/
75+
public function getLSEN()
76+
{
77+
return $this->lsen;
78+
}
79+
80+
/**
81+
* Sets a new namespace.
82+
*
83+
* Sets a new namespace for the context. Leading and trailing slashes are
84+
* trimmed, and the keywords "global" and "default" are treated as aliases
85+
* to no namespace.
86+
*
87+
* @param string $namespace The new namespace to set.
88+
*
89+
* @return $this
90+
*/
91+
public function setNamespace($namespace)
92+
{
93+
if ('global' !== $namespace
94+
&& 'default' !== $namespace
95+
) {
96+
// Srip leading and trailing slash
97+
$this->namespace = trim((string)$namespace, '\\');
98+
} else {
99+
$this->namespace = '';
100+
}
101+
return $this;
102+
}
103+
104+
/**
105+
* Sets the namespace aliases, replacing all previous ones.
106+
*
107+
* @param array $namespace_aliases List of namespace aliases => Fully
108+
* Qualified Namespace.
109+
*
110+
* @return $this
111+
*/
112+
public function setNamespaceAliases(array $namespace_aliases)
113+
{
114+
$this->namespace_aliases = array();
115+
foreach ($namespace_aliases as $alias => $fqnn) {
116+
$this->setNamespaceAlias($alias, $fqnn);
117+
}
118+
return $this;
119+
}
120+
121+
/**
122+
* Adds a namespace alias to the context.
123+
*
124+
* @param string $alias The alias name (the part after "as", or the last
125+
* part of the Fully Qualified Namespace Name) to add.
126+
* @param string $fqnn The Fully Qualified Namespace Name for this alias.
127+
* Any form of leading/trailing slashes are accepted, but what will be
128+
* stored is a name, prefixed with a slash, and no trailing slash.
129+
*
130+
* @return $this
131+
*/
132+
public function setNamespaceAlias($alias, $fqnn)
133+
{
134+
$this->namespace_aliases[$alias] = '\\' . trim((string)$fqnn, '\\');
135+
return $this;
136+
}
137+
138+
/**
139+
* Sets a new Local Structural Element Name.
140+
*
141+
* Sets a new Local Structural Element Name. A local name also contains
142+
* punctuation determining the kind of structural element (e.g. trailing "("
143+
* and ")" for functions and methods).
144+
*
145+
* @param string $lsen The new local name of a structural element.
146+
*
147+
* @return $this
148+
*/
149+
public function setLSEN($lsen)
150+
{
151+
$this->lsen = (string)$lsen;
152+
return $this;
153+
}
154+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
/**
3+
* phpDocumentor
4+
*
5+
* PHP Version 5.3
6+
*
7+
* @author Vasil Rangelov <[email protected]>
8+
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
9+
* @license http://www.opensource.org/licenses/mit-license.php MIT
10+
* @link http://phpdoc.org
11+
*/
12+
13+
namespace phpDocumentor\Reflection\DocBlock;
14+
15+
/**
16+
* The location a DocBlock occurs within a file.
17+
*
18+
* @author Vasil Rangelov <[email protected]>
19+
* @license http://www.opensource.org/licenses/mit-license.php MIT
20+
* @link http://phpdoc.org
21+
*/
22+
class Location
23+
{
24+
/** @var int Line where the DocBlock text starts. */
25+
protected $line_number = 0;
26+
27+
/** @var int Column where the DocBlock text starts. */
28+
protected $column_number = 0;
29+
30+
public function __construct(
31+
$line_number = 0,
32+
$column_number = 0
33+
) {
34+
$this->line_number = (int)$line_number;
35+
$this->column_number = (int)$column_number;
36+
}
37+
38+
/**
39+
* @return int Line where the DocBlock text starts.
40+
*/
41+
public function getLineNumber()
42+
{
43+
return $this->line_number;
44+
}
45+
46+
/**
47+
* @return int Column where the DocBlock text starts.
48+
*/
49+
public function getColumnNumber()
50+
{
51+
return $this->column_number;
52+
}
53+
}

0 commit comments

Comments
 (0)