11<?php
22class PHPCtags
33{
4- const VERSION = '0.4.2 ' ;
4+ const VERSION = '0.5 ' ;
55
66 private $ mFile ;
77
88 private $ mFiles ;
99
1010 private static $ mKinds = array (
11+ 't ' => 'trait ' ,
1112 'c ' => 'class ' ,
1213 'm ' => 'method ' ,
1314 'f ' => 'function ' ,
1415 'p ' => 'property ' ,
1516 'd ' => 'constant ' ,
1617 'v ' => 'variable ' ,
1718 'i ' => 'interface ' ,
19+ 'n ' => 'namespace ' ,
1820 );
1921
2022 private $ mParser ;
@@ -111,7 +113,8 @@ private function struct($node, $reset=FALSE, $parent=array())
111113 $ structs = array ();
112114 }
113115
114- $ kind = $ name = $ line = $ access = '' ;
116+ $ kind = $ name = $ line = $ access = $ extends = '' ;
117+ $ implements = array ();
115118
116119 if (!empty ($ parent )) array_push ($ scope , $ parent );
117120
@@ -122,6 +125,8 @@ private function struct($node, $reset=FALSE, $parent=array())
122125 } elseif ($ node instanceof PHPParser_Node_Stmt_Class) {
123126 $ kind = 'c ' ;
124127 $ name = $ node ->name ;
128+ $ extends = $ node ->extends ;
129+ $ implements = $ node ->implements ;
125130 $ line = $ node ->getLine ();
126131 foreach ($ node as $ subNode ) {
127132 $ this ->struct ($ subNode , FALSE , array ('class ' => $ name ));
@@ -181,10 +186,19 @@ private function struct($node, $reset=FALSE, $parent=array())
181186 foreach ($ node as $ subNode ) {
182187 $ this ->struct ($ subNode , FALSE , array ('interface ' => $ name ));
183188 }
189+ } elseif ($ node instanceof PHPParser_Node_Stmt_Trait ) {
190+ $ kind = 't ' ;
191+ $ name = $ node ->name ;
192+ $ line = $ node ->getLine ();
193+ foreach ($ node as $ subNode ) {
194+ $ this ->struct ($ subNode , FALSE , array ('trait ' => $ name ));
195+ }
184196 } elseif ($ node instanceof PHPParser_Node_Stmt_Namespace) {
185- //@todo
197+ $ kind = 'n ' ;
198+ $ name = $ node ->name ;
199+ $ line = $ node ->getLine ();
186200 foreach ($ node as $ subNode ) {
187- $ this ->struct ($ subNode );
201+ $ this ->struct ($ subNode, FALSE , array ( ' namespace ' => $ name ) );
188202 }
189203 } elseif ($ node instanceof PHPParser_Node_Expr_Assign) {
190204 if (is_string ($ node ->var ->name )) {
@@ -218,6 +232,8 @@ private function struct($node, $reset=FALSE, $parent=array())
218232 'file ' => $ this ->mFile ,
219233 'kind ' => $ kind ,
220234 'name ' => $ name ,
235+ 'extends ' => $ extends ,
236+ 'implements ' => $ implements ,
221237 'line ' => $ line ,
222238 'scope ' => $ scope ,
223239 'access ' => $ access ,
@@ -283,19 +299,54 @@ private function render()
283299
284300 #field=s
285301 if (in_array ('s ' , $ this ->mOptions ['fields ' ]) && !empty ($ struct ['scope ' ])) {
302+ // $scope, $type, $name are current scope variables
286303 $ scope = array_pop ($ struct ['scope ' ]);
287304 list ($ type , $ name ) = each ($ scope );
288305 switch ($ type ) {
306+ case 'class ' :
307+ // n_* stuffs are namespace related scope variables
308+ // current > class > namespace
309+ $ n_scope = array_pop ($ struct ['scope ' ]);
310+ if (!empty ($ n_scope )) {
311+ list ($ n_type , $ n_name ) = each ($ n_scope );
312+ $ s_str = 'class: ' . $ n_name . '\\' . $ name ;
313+ } else {
314+ $ s_str = 'class: ' . $ name ;
315+ }
316+ break ;
289317 case 'method ' :
290- $ scope = array_pop ($ struct ['scope ' ]);
291- list ($ p_type , $ p_name ) = each ($ scope );
292- $ scope = 'method: ' . $ p_name . ':: ' . $ name ;
318+ // c_* stuffs are class related scope variables
319+ // current > method > class > namespace
320+ $ c_scope = array_pop ($ struct ['scope ' ]);
321+ list ($ c_type , $ c_name ) = each ($ c_scope );
322+ $ n_scope = array_pop ($ struct ['scope ' ]);
323+ if (!empty ($ n_scope )) {
324+ list ($ n_type , $ n_name ) = each ($ n_scope );
325+ $ s_str = 'method: ' . $ n_name . '\\' . $ c_name . ':: ' . $ name ;
326+ } else {
327+ $ s_str = 'method: ' . $ c_name . ':: ' . $ name ;
328+ }
293329 break ;
294330 default :
295- $ scope = $ type . ': ' . $ name ;
331+ $ s_str = $ type . ': ' . $ name ;
296332 break ;
297333 }
298- $ str .= "\t" . $ scope ;
334+ $ str .= "\t" . $ s_str ;
335+ }
336+
337+ #field=i
338+ if (in_array ('i ' , $ this ->mOptions ['fields ' ])) {
339+ $ inherits = array ();
340+ if (!empty ($ struct ['extends ' ])) {
341+ $ inherits [] = $ struct ['extends ' ]->toString ();
342+ }
343+ if (!empty ($ struct ['implements ' ])) {
344+ foreach ($ struct ['implements ' ] as $ interface ) {
345+ $ inherits [] = $ interface ->toString ();
346+ }
347+ }
348+ if (!empty ($ inherits ))
349+ $ str .= "\t" . 'inherits: ' . implode (', ' , $ inherits );
299350 }
300351
301352 #field=a
0 commit comments