1
1
<?php
2
2
/**
3
- * phpDocumentor
3
+ * This file is part of phpDocumentor.
4
4
*
5
- * PHP Version 5.3
5
+ * For the full copyright and license information, please view the LICENSE
6
+ * file that was distributed with this source code.
6
7
*
7
- * @author Vasil Rangelov <[email protected] >
8
- * @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
8
+ * @copyright 2010-2015 Mike van Riel<[email protected] >
9
9
* @license http://www.opensource.org/licenses/mit-license.php MIT
10
10
* @link http://phpdoc.org
11
11
*/
12
12
13
13
namespace phpDocumentor \Reflection \DocBlock \Tags ;
14
14
15
- use phpDocumentor \Reflection \DocBlock \Tag ;
15
+ use phpDocumentor \Reflection \DocBlock \Description ;
16
+ use phpDocumentor \Reflection \DocBlock \DescriptionFactory ;
17
+ use phpDocumentor \Reflection \Types \Context ;
18
+ use Webmozart \Assert \Assert ;
16
19
17
20
/**
18
- * Reflection class for a @ source tag in a Docblock.
21
+ * Reflection class for a {@} source tag in a Docblock.
19
22
*/
20
- class Source extends Tag
23
+ final class Source extends BaseTag
21
24
{
22
- /**
23
- * @var int The starting line, relative to the structural element's
24
- * location.
25
- */
26
- protected $ startingLine = 1 ;
25
+ /** @var string */
26
+ protected $ name = 'source ' ;
27
27
28
- /**
29
- * @var int|null The number of lines, relative to the starting line. NULL
30
- * means "to the end".
31
- */
32
- protected $ lineCount = null ;
28
+ /** @var int The starting line, relative to the structural element's location. */
29
+ private $ startingLine = 1 ;
33
30
34
- /**
35
- * {@inheritdoc}
36
- */
37
- public function getContent ( )
31
+ /** @var int|null The number of lines, relative to the starting line. NULL means "to the end". */
32
+ private $ lineCount = null ;
33
+
34
+ public function __construct ( $ startingLine , $ lineCount = null , Description $ description = null )
38
35
{
39
- if (null === $ this ->description ) {
40
- $ this ->description
41
- = "{$ this ->startingLine } {$ this ->lineCount } {$ this ->description }" ;
42
- }
36
+ Assert::integerish ($ startingLine );
37
+ Assert::nullOrIntegerish ($ lineCount );
43
38
44
- return $ this ->description ;
39
+ $ this ->startingLine = (int )$ startingLine ;
40
+ $ this ->lineCount = $ lineCount !== null ? (int )$ lineCount : null ;
41
+ $ this ->description = $ description ;
45
42
}
46
43
47
44
/**
48
45
* {@inheritdoc}
49
46
*/
50
- public function setContent ( $ content )
47
+ public static function create ( $ body , DescriptionFactory $ descriptionFactory = null , Context $ context = null )
51
48
{
52
- parent ::setContent ($ content );
53
- if (preg_match (
54
- '/^
55
- # Starting line
56
- ([1-9]\d*)
57
- \s*
58
- # Number of lines
59
- (?:
60
- ((?1))
61
- \s+
62
- )?
63
- # Description
64
- (.*)
65
- $/sux ' ,
66
- $ this ->description ,
67
- $ matches
68
- )) {
69
- $ this ->startingLine = (int )$ matches [1 ];
70
- if (isset ($ matches [2 ]) && '' !== $ matches [2 ]) {
71
- $ this ->lineCount = (int )$ matches [2 ];
49
+ Assert::stringNotEmpty ($ body );
50
+ Assert::notNull ($ descriptionFactory );
51
+
52
+ $ startingLine = 1 ;
53
+ $ lineCount = null ;
54
+ $ description = null ;
55
+
56
+ // Starting line / Number of lines / Description
57
+ if (preg_match ('/^([1-9]\d*)\s*(?:((?1))\s+)?(.*)$/sux ' , $ body , $ matches )) {
58
+ $ startingLine = (int )$ matches [1 ];
59
+ if (isset ($ matches [2 ]) && $ matches [2 ] !== '' ) {
60
+ $ lineCount = (int )$ matches [2 ];
72
61
}
73
- $ this ->setDescription ($ matches [3 ]);
74
- $ this ->description = $ content ;
62
+ $ description = $ matches [3 ];
75
63
}
76
64
77
- return $ this ;
65
+ return new static ( $ startingLine , $ lineCount , $ descriptionFactory -> create ( $ description , $ context )) ;
78
66
}
79
67
80
68
/**
@@ -88,22 +76,6 @@ public function getStartingLine()
88
76
return $ this ->startingLine ;
89
77
}
90
78
91
- /**
92
- * Sets the starting line.
93
- *
94
- * @param int $startingLine The new starting line, relative to the
95
- * structural element's location.
96
- *
97
- * @return $this
98
- */
99
- public function setStartingLine ($ startingLine )
100
- {
101
- $ this ->startingLine = $ startingLine ;
102
-
103
- $ this ->description = null ;
104
- return $ this ;
105
- }
106
-
107
79
/**
108
80
* Returns the number of lines.
109
81
*
@@ -115,19 +87,10 @@ public function getLineCount()
115
87
return $ this ->lineCount ;
116
88
}
117
89
118
- /**
119
- * Sets the number of lines.
120
- *
121
- * @param int|null $lineCount The new number of lines, relative to the
122
- * starting line. NULL means "to the end".
123
- *
124
- * @return $this
125
- */
126
- public function setLineCount ($ lineCount )
90
+ public function __toString ()
127
91
{
128
- $ this ->lineCount = $ lineCount ;
129
-
130
- $ this ->description = null ;
131
- return $ this ;
92
+ return $ this ->startingLine
93
+ . ($ this ->lineCount !== null ? ' ' . $ this ->lineCount : '' )
94
+ . ($ this ->description ? ' ' . $ this ->description ->render () : '' );
132
95
}
133
96
}
0 commit comments