|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of phpDocumentor. |
|
4
|
|
|
* |
|
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
6
|
|
|
* file that was distributed with this source code. |
|
7
|
|
|
* |
|
8
|
|
|
* @copyright 2010-2015 Mike van Riel<[email protected]> |
|
9
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
|
10
|
|
|
* @link http://phpdoc.org |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
namespace phpDocumentor\Reflection\Php\Factory; |
|
15
|
|
|
|
|
16
|
|
|
use phpDocumentor\Reflection\Fqsen; |
|
17
|
|
|
use PhpParser\Comment\Doc; |
|
18
|
|
|
use PhpParser\Node\Stmt\ClassConst; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* This class acts like a combination of a ClassConst and Const_ to be able to create constant descriptors using a normal strategy. |
|
22
|
|
|
*/ |
|
23
|
|
|
final class ClassConstantIterator implements \Iterator |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @var ClassConst |
|
27
|
|
|
*/ |
|
28
|
|
|
private $classConstants; |
|
29
|
|
|
|
|
30
|
|
|
/** @var int index of the current ClassConst to use */ |
|
31
|
|
|
private $index = 0; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Initializes the class with source data. |
|
35
|
|
|
* |
|
36
|
|
|
* @param ClassConst $classConst |
|
37
|
|
|
*/ |
|
38
|
1 |
|
public function __construct(ClassConst $classConst) |
|
39
|
|
|
{ |
|
40
|
1 |
|
$this->classConstants = $classConst; |
|
41
|
1 |
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Gets line the node started in. |
|
45
|
|
|
* |
|
46
|
|
|
* @return int Line |
|
47
|
|
|
*/ |
|
48
|
1 |
|
public function getLine() |
|
49
|
|
|
{ |
|
50
|
1 |
|
return $this->classConstants->getLine(); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Returns the name of the current constant. |
|
55
|
|
|
* |
|
56
|
|
|
* @return string |
|
57
|
|
|
*/ |
|
58
|
1 |
|
public function getName() |
|
59
|
|
|
{ |
|
60
|
1 |
|
return $this->classConstants->consts[$this->index]->name; |
|
|
|
|
|
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Returns the fqsen of the current constant. |
|
65
|
|
|
* |
|
66
|
|
|
* @return Fqsen |
|
67
|
|
|
*/ |
|
68
|
1 |
|
public function getFqsen() |
|
69
|
|
|
{ |
|
70
|
1 |
|
return $this->classConstants->consts[$this->index]->fqsen; |
|
|
|
|
|
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Gets the doc comment of the node. |
|
75
|
|
|
* |
|
76
|
|
|
* The doc comment has to be the last comment associated with the node. |
|
77
|
|
|
* |
|
78
|
|
|
* @return null|Doc Doc comment object or null |
|
79
|
|
|
*/ |
|
80
|
2 |
|
public function getDocComment() |
|
81
|
|
|
{ |
|
82
|
2 |
|
$docComment = $this->classConstants->consts[$this->index]->getDocComment(); |
|
83
|
2 |
|
if ($docComment === null) { |
|
84
|
1 |
|
$docComment = $this->classConstants->getDocComment(); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
2 |
|
return $docComment; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function getValue() |
|
91
|
|
|
{ |
|
92
|
|
|
return $this->classConstants->consts[$this->index]->value; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* (PHP 5 >= 5.0.0)<br/> |
|
97
|
|
|
* Return the current element |
|
98
|
|
|
* @link http://php.net/manual/en/iterator.current.php |
|
99
|
|
|
* @return mixed Can return any type. |
|
100
|
|
|
*/ |
|
101
|
1 |
|
public function current() |
|
102
|
|
|
{ |
|
103
|
1 |
|
return $this; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* (PHP 5 >= 5.0.0)<br/> |
|
108
|
|
|
* Move forward to next element |
|
109
|
|
|
* @link http://php.net/manual/en/iterator.next.php |
|
110
|
|
|
* @return void Any returned value is ignored. |
|
111
|
|
|
*/ |
|
112
|
2 |
|
public function next() |
|
113
|
|
|
{ |
|
114
|
2 |
|
$this->index++; |
|
115
|
2 |
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* (PHP 5 >= 5.0.0)<br/> |
|
119
|
|
|
* Return the key of the current element |
|
120
|
|
|
* @link http://php.net/manual/en/iterator.key.php |
|
121
|
|
|
* @return mixed scalar on success, or null on failure. |
|
122
|
|
|
*/ |
|
123
|
1 |
|
public function key() |
|
124
|
|
|
{ |
|
125
|
1 |
|
return $this->index; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* (PHP 5 >= 5.0.0)<br/> |
|
130
|
|
|
* Checks if current position is valid |
|
131
|
|
|
* @link http://php.net/manual/en/iterator.valid.php |
|
132
|
|
|
* @return boolean The return value will be casted to boolean and then evaluated. |
|
133
|
|
|
* Returns true on success or false on failure. |
|
134
|
|
|
*/ |
|
135
|
1 |
|
public function valid() |
|
136
|
|
|
{ |
|
137
|
1 |
|
return isset($this->classConstants->consts[$this->index]); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* (PHP 5 >= 5.0.0)<br/> |
|
142
|
|
|
* Rewind the Iterator to the first element |
|
143
|
|
|
* @link http://php.net/manual/en/iterator.rewind.php |
|
144
|
|
|
* @return void Any returned value is ignored. |
|
145
|
|
|
*/ |
|
146
|
1 |
|
public function rewind() |
|
147
|
|
|
{ |
|
148
|
1 |
|
$this->index = 0; |
|
149
|
1 |
|
} |
|
150
|
|
|
} |
|
151
|
|
|
|