@@ -15,9 +15,12 @@ class PHPCtags
1515
1616 private $ mParser ;
1717
18- public function __construct ()
18+ private $ mOptions ;
19+
20+ public function __construct ($ options )
1921 {
2022 $ this ->mParser = new PHPParser_Parser (new PHPParser_Lexer );
23+ $ this ->mOptions = $ options ;
2124 }
2225
2326 public function setMFile ($ file )
@@ -198,14 +201,14 @@ private function struct($node, $reset=FALSE, $parent=array())
198201 if (!empty ($ parent )) array_pop ($ scope );
199202
200203 // if no --sort is given, sort by occurrence
201- if (!isset ($ options ['sort ' ]) || $ options ['sort ' ] == 'no ' ) {
204+ if (!isset ($ this -> mOptions ['sort ' ]) || $ this -> mOptions ['sort ' ] == 'no ' ) {
202205 usort ($ structs , 'self::helperSortByLine ' );
203206 }
204207
205208 return $ structs ;
206209 }
207210
208- private function render ($ structs, $ options )
211+ private function render ($ structs )
209212 {
210213 $ str = '' ;
211214 foreach ($ structs as $ struct ) {
@@ -223,37 +226,37 @@ private function render($structs, $options)
223226
224227 $ str .= "\t" . $ file ;
225228
226- if ($ options ['excmd ' ] == 'number ' ) {
229+ if ($ this -> mOptions ['excmd ' ] == 'number ' ) {
227230 $ str .= "\t" . $ struct ['line ' ];
228231 } else { //excmd == 'mixed' or 'pattern', default behavior
229232 $ str .= "\t" . "/^ " . rtrim ($ lines [$ struct ['line ' ] - 1 ], "\n" ) . "$/ " ;
230233 }
231234
232- if ($ options ['format ' ] == 1 ) {
235+ if ($ this -> mOptions ['format ' ] == 1 ) {
233236 $ str .= "\n" ;
234237 continue ;
235238 }
236239
237240 $ str .= "; \"" ;
238241
239242 #field=k, kind of tag as single letter
240- if (in_array ('k ' , $ options ['fields ' ])) {
241- in_array ('z ' , $ options ['fields ' ]) && $ str .= "kind: " ;
243+ if (in_array ('k ' , $ this -> mOptions ['fields ' ])) {
244+ in_array ('z ' , $ this -> mOptions ['fields ' ]) && $ str .= "kind: " ;
242245 $ str .= "\t" . $ struct ['kind ' ];
243246 } else
244247 #field=K, kind of tag as fullname
245- if (in_array ('K ' , $ options ['fields ' ])) {
246- in_array ('z ' , $ options ['fields ' ]) && $ str .= "kind: " ;
248+ if (in_array ('K ' , $ this -> mOptions ['fields ' ])) {
249+ in_array ('z ' , $ this -> mOptions ['fields ' ]) && $ str .= "kind: " ;
247250 $ str .= "\t" . self ::$ mKinds [$ struct ['kind ' ]];
248251 }
249252
250253 #field=n
251- if (in_array ('n ' , $ options ['fields ' ])) {
254+ if (in_array ('n ' , $ this -> mOptions ['fields ' ])) {
252255 $ str .= "\t" . "line: " . $ struct ['line ' ];
253256 }
254257
255258 #field=s
256- if (in_array ('s ' , $ options ['fields ' ]) && !empty ($ struct ['scope ' ])) {
259+ if (in_array ('s ' , $ this -> mOptions ['fields ' ]) && !empty ($ struct ['scope ' ])) {
257260 $ scope = array_pop ($ struct ['scope ' ]);
258261 list ($ type , $ name ) = each ($ scope );
259262 switch ($ type ) {
@@ -270,7 +273,7 @@ private function render($structs, $options)
270273 }
271274
272275 #field=a
273- if (in_array ('a ' , $ options ['fields ' ]) && !empty ($ struct ['access ' ])) {
276+ if (in_array ('a ' , $ this -> mOptions ['fields ' ]) && !empty ($ struct ['access ' ])) {
274277 $ str .= "\t" . "access: " . $ struct ['access ' ];
275278 }
276279
@@ -281,17 +284,17 @@ private function render($structs, $options)
281284 $ str = trim ($ str );
282285
283286 // sort the result as instructed
284- if (isset ($ options ['sort ' ]) && ($ options ['sort ' ] == 'yes ' || $ options ['sort ' ] == 'foldcase ' )) {
285- $ str = self ::stringSortByLine ($ str , $ options ['sort ' ] == 'foldcase ' );
287+ if (isset ($ this -> mOptions ['sort ' ]) && ($ this -> mOptions ['sort ' ] == 'yes ' || $ this -> mOptions ['sort ' ] == 'foldcase ' )) {
288+ $ str = self ::stringSortByLine ($ str , $ this -> mOptions ['sort ' ] == 'foldcase ' );
286289 }
287290
288291 return $ str ;
289292 }
290293
291- public function export ($ file, $ options )
294+ public function export ($ file )
292295 {
293296 $ structs = array ();
294- if (is_dir ($ file ) && isset ($ options ['R ' ])) {
297+ if (is_dir ($ file ) && isset ($ this -> mOptions ['R ' ])) {
295298 $ iterator = new RecursiveIteratorIterator (
296299 new RecursiveDirectoryIterator (
297300 $ file ,
@@ -307,7 +310,7 @@ public function export($file, $options)
307310 continue ;
308311 }
309312
310- if (isset ($ options ['exclude ' ]) && false !== strpos ($ filename , $ options ['exclude ' ])) {
313+ if (isset ($ this -> mOptions ['exclude ' ]) && false !== strpos ($ filename , $ this -> mOptions ['exclude ' ])) {
311314 continue ;
312315 }
313316
@@ -318,7 +321,7 @@ public function export($file, $options)
318321 $ this ->setMFile ($ file );
319322 $ structs += $ this ->struct ($ this ->mParser ->parse (file_get_contents ($ this ->mFile )), TRUE );
320323 }
321- return $ this ->render ($ structs, $ options );
324+ return $ this ->render ($ structs );
322325 }
323326}
324327
0 commit comments