3400220ea7c791a629c599b54a332d0f3a88f306
[yaffs-website] / vendor / phpdocumentor / reflection-docblock / src / phpDocumentor / Reflection / DocBlock / Tag / SourceTag.php
1 <?php
2 /**
3  * phpDocumentor
4  *
5  * PHP Version 5.3
6  *
7  * @author    Vasil Rangelov <boen.robot@gmail.com>
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\Tag;
14
15 use phpDocumentor\Reflection\DocBlock\Tag;
16
17 /**
18  * Reflection class for a @source tag in a Docblock.
19  *
20  * @author  Vasil Rangelov <boen.robot@gmail.com>
21  * @license http://www.opensource.org/licenses/mit-license.php MIT
22  * @link    http://phpdoc.org
23  */
24 class SourceTag extends Tag
25 {
26     /**
27      * @var int The starting line, relative to the structural element's
28      *     location.
29      */
30     protected $startingLine = 1;
31
32     /** 
33      * @var int|null The number of lines, relative to the starting line. NULL
34      *     means "to the end".
35      */
36     protected $lineCount = null;
37
38     /**
39      * {@inheritdoc}
40      */
41     public function getContent()
42     {
43         if (null === $this->content) {
44             $this->content
45                 = "{$this->startingLine} {$this->lineCount} {$this->description}";
46         }
47
48         return $this->content;
49     }
50
51     /**
52      * {@inheritdoc}
53      */
54     public function setContent($content)
55     {
56         parent::setContent($content);
57         if (preg_match(
58             '/^
59                 # Starting line
60                 ([1-9]\d*)
61                 \s*
62                 # Number of lines
63                 (?:
64                     ((?1))
65                     \s+
66                 )?
67                 # Description
68                 (.*)
69             $/sux',
70             $this->description,
71             $matches
72         )) {
73             $this->startingLine = (int)$matches[1];
74             if (isset($matches[2]) && '' !== $matches[2]) {
75                 $this->lineCount = (int)$matches[2];
76             }
77             $this->setDescription($matches[3]);
78             $this->content = $content;
79         }
80
81         return $this;
82     }
83
84     /**
85      * Gets the starting line.
86      *
87      * @return int The starting line, relative to the structural element's
88      *     location.
89      */
90     public function getStartingLine()
91     {
92         return $this->startingLine;
93     }
94
95     /**
96      * Sets the starting line.
97      * 
98      * @param int $startingLine The new starting line, relative to the
99      *     structural element's location.
100      * 
101      * @return $this
102      */
103     public function setStartingLine($startingLine)
104     {
105         $this->startingLine = $startingLine;
106
107         $this->content = null;
108         return $this;
109     }
110
111     /**
112      * Returns the number of lines.
113      *
114      * @return int|null The number of lines, relative to the starting line. NULL
115      *     means "to the end".
116      */
117     public function getLineCount()
118     {
119         return $this->lineCount;
120     }
121
122     /**
123      * Sets the number of lines.
124      * 
125      * @param int|null $lineCount The new number of lines, relative to the
126      *     starting line. NULL means "to the end".
127      * 
128      * @return $this
129      */
130     public function setLineCount($lineCount)
131     {
132         $this->lineCount = $lineCount;
133
134         $this->content = null;
135         return $this;
136     }
137 }