@@ -7,12 +7,8 @@ class PHPCtags
77
88 private $ mParser ;
99
10- private $ mOptions ;
11-
12- public function __construct ($ file , $ options =array ())
10+ public function __construct ()
1311 {
14- //@todo Check for existence
15- $ this ->mFile = $ file ;
1612 $ this ->mKinds = array (
1713 'c ' => 'class ' ,
1814 'm ' => 'method ' ,
@@ -23,7 +19,6 @@ public function __construct($file, $options=array())
2319 'i ' => 'interface ' ,
2420 );
2521 $ this ->mParser = new PHPParser_Parser (new PHPParser_Lexer );
26- $ this ->mOptions = $ options ;
2722 }
2823
2924 private function getNodeAccess ($ node )
@@ -143,7 +138,7 @@ private function struct($node, $parent=array())
143138 return $ structs ;
144139 }
145140
146- private function render ($ structs )
141+ private function render ($ structs, $ options )
147142 {
148143 $ str = '' ;
149144 $ lines = file ($ this ->mFile );
@@ -159,37 +154,37 @@ private function render($structs)
159154
160155 $ str .= "\t" . $ this ->mFile ;
161156
162- if ($ this -> mOptions ['excmd ' ] == 'number ' ) {
157+ if ($ options ['excmd ' ] == 'number ' ) {
163158 $ str .= "\t" . $ struct ['line ' ];
164159 } else { //excmd == 'mixed' or 'pattern', default behavior
165160 $ str .= "\t" . "/^ " . rtrim ($ lines [$ struct ['line ' ] - 1 ], "\n" ) . "$/ " ;
166161 }
167162
168- if ($ this -> mOptions ['format ' ] == 1 ) {
163+ if ($ options ['format ' ] == 1 ) {
169164 $ str .= "\n" ;
170165 continue ;
171166 }
172167
173168 $ str .= "; \"" ;
174169
175170 #field=k, kind of tag as single letter
176- if (in_array ('k ' , $ this -> mOptions ['fields ' ])) {
177- in_array ('z ' , $ this -> mOptions ['fields ' ]) && $ str .= "kind: " ;
171+ if (in_array ('k ' , $ options ['fields ' ])) {
172+ in_array ('z ' , $ options ['fields ' ]) && $ str .= "kind: " ;
178173 $ str .= "\t" . $ struct ['kind ' ];
179174 } else
180175 #field=K, kind of tag as fullname
181- if (in_array ('K ' , $ this -> mOptions ['fields ' ])) {
182- in_array ('z ' , $ this -> mOptions ['fields ' ]) && $ str .= "kind: " ;
176+ if (in_array ('K ' , $ options ['fields ' ])) {
177+ in_array ('z ' , $ options ['fields ' ]) && $ str .= "kind: " ;
183178 $ str .= "\t" . $ this ->mKinds [$ struct ['kind ' ]];
184179 }
185180
186181 #field=n
187- if (in_array ('n ' , $ this -> mOptions ['fields ' ])) {
182+ if (in_array ('n ' , $ options ['fields ' ])) {
188183 $ str .= "\t" . "line: " . $ struct ['line ' ];
189184 }
190185
191186 #field=s
192- if (in_array ('s ' , $ this -> mOptions ['fields ' ]) && !empty ($ struct ['scope ' ])) {
187+ if (in_array ('s ' , $ options ['fields ' ]) && !empty ($ struct ['scope ' ])) {
193188 $ scope = array_pop ($ struct ['scope ' ]);
194189 list ($ type ,$ name ) = each ($ scope );
195190 switch ($ type ) {
@@ -206,7 +201,7 @@ private function render($structs)
206201 }
207202
208203 #field=a
209- if (in_array ('a ' , $ this -> mOptions ['fields ' ]) && !empty ($ struct ['access ' ])) {
204+ if (in_array ('a ' , $ options ['fields ' ]) && !empty ($ struct ['access ' ])) {
210205 $ str .= "\t" . "access: " . $ struct ['access ' ];
211206 }
212207
@@ -215,9 +210,11 @@ private function render($structs)
215210 return $ str ;
216211 }
217212
218- public function export ()
213+ public function export ($ file , $ options )
219214 {
215+ //@todo Check for existence
216+ $ this ->mFile = $ file ;
220217 $ structs = $ this ->struct ($ this ->mParser ->parse (file_get_contents ($ this ->mFile )));
221- echo $ this ->render ($ structs );
218+ echo $ this ->render ($ structs, $ options );
222219 }
223220}
0 commit comments