1 | <?php |
||
39 | abstract class AbstractParser implements ParserInterface |
||
40 | { |
||
41 | |||
42 | /** |
||
43 | * The aspect of the configuration we need |
||
44 | * |
||
45 | * @var \AppserverIo\Doppelgaenger\Config $config |
||
46 | */ |
||
47 | protected $config; |
||
48 | |||
49 | /** |
||
50 | * The path of the file we want to parse |
||
51 | * |
||
52 | * @var string $file |
||
53 | */ |
||
54 | protected $file; |
||
55 | |||
56 | /** |
||
57 | * The token array representing the whole file |
||
58 | * |
||
59 | * @var array $tokens |
||
60 | */ |
||
61 | protected $tokens = array(); |
||
62 | |||
63 | /** |
||
64 | * The count of our main token array, so we do not have to calculate it over and over again |
||
65 | * |
||
66 | * @var integer $tokenCount |
||
67 | */ |
||
68 | protected $tokenCount; |
||
69 | |||
70 | /** |
||
71 | * The current definition we are working on. |
||
72 | * This should be filled during parsing and should be passed down to whatever parser we need so we know about |
||
73 | * the current "parent" definition parts. |
||
74 | * |
||
75 | * @var \AppserverIo\Doppelgaenger\Interfaces\StructureDefinitionInterface $currentDefinition |
||
76 | */ |
||
77 | protected $currentDefinition; |
||
78 | |||
79 | /** |
||
80 | * The list of structures (within this hierarchy) which we already parsed. |
||
81 | * |
||
82 | * @var \AppserverIo\Doppelgaenger\Entities\Definitions\StructureDefinitionHierarchy $structureDefinitionHierarchy |
||
83 | */ |
||
84 | protected $structureDefinitionHierarchy; |
||
85 | |||
86 | /** |
||
87 | * Our structure map instance |
||
88 | * |
||
89 | * @var \AppserverIo\Doppelgaenger\StructureMap $structureMap |
||
90 | */ |
||
91 | protected $structureMap; |
||
92 | |||
93 | /** |
||
94 | * Default constructor |
||
95 | * |
||
96 | * @param string $file The path of the file we want to parse |
||
97 | * @param \AppserverIo\Doppelgaenger\Config $config Configuration |
||
98 | * @param StructureDefinitionHierarchy $structureDefinitionHierarchy List of already parsed structures |
||
99 | * @param \AppserverIo\Doppelgaenger\StructureMap|null $structureMap Our structure map instance |
||
100 | * @param StructureDefinitionInterface|null $currentDefinition The current definition we are working on |
||
101 | * @param array $tokens The array of tokens taken from the file |
||
102 | * |
||
103 | * @throws \AppserverIo\Doppelgaenger\Exceptions\ParserException |
||
104 | */ |
||
105 | public function __construct( |
||
139 | |||
140 | /** |
||
141 | * Does a certain block of code contain a certain keyword |
||
142 | * |
||
143 | * @param string $docBlock The code block to search in |
||
144 | * @param string $keyword The keyword to search for |
||
145 | * |
||
146 | * @return boolean |
||
147 | */ |
||
148 | protected function usesKeyword( |
||
158 | |||
159 | /** |
||
160 | * Get the starting line of the structure, FALSE if unknown |
||
161 | * |
||
162 | * @param array $tokens The token array |
||
163 | * |
||
164 | * @return integer|boolean |
||
165 | */ |
||
166 | protected function getStartLine($tokens) |
||
181 | |||
182 | /** |
||
183 | * Get the ending line of the structure, FALSE if unknown |
||
184 | * |
||
185 | * @param array $tokens The token array |
||
186 | * |
||
187 | * @return integer|boolean |
||
188 | */ |
||
189 | protected function getEndLine($tokens) |
||
209 | |||
210 | /** |
||
211 | * Will search for a certain token in a certain entity. |
||
212 | * |
||
213 | * This method will search the signature of either a class or a function for a certain token e.g. final. |
||
214 | * Will return true if the token is found, and false if not or an error occurred. |
||
215 | * |
||
216 | * @param array $tokens The token array to search in |
||
217 | * @param integer $searchedToken The token we search for, use PHP tokens here |
||
218 | * @param integer $parsedEntity The type of entity we search in front of, use PHP tokens here |
||
219 | * |
||
220 | * @return boolean |
||
221 | */ |
||
222 | protected function hasSignatureToken( |
||
256 | |||
257 | /** |
||
258 | * Will return the DocBlock of a certain construct based on the token identifying it. |
||
259 | * Will return an empty string if none is found |
||
260 | * |
||
261 | * @param array $tokens The token array to search in |
||
262 | * @param integer $structureToken The type of entity we search in front of, use PHP tokens here e.g. T_CLASS |
||
263 | * |
||
264 | * @return string |
||
265 | */ |
||
266 | protected function getDocBlock($tokens, $structureToken) |
||
301 | } |
||
302 |