Skip to content

Commit 42c299d

Browse files
committed
Merge branch 'release/0.5'
2 parents 94553de + ec6a1c8 commit 42c299d

File tree

4 files changed

+76
-13
lines changed

4 files changed

+76
-13
lines changed

ChangeLog.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
Version 0.5
2+
-----------
3+
4+
* Add trait support
5+
thanks to Mark Wu
6+
* Add inherits support
7+
thanks to Mark Wu
8+
* Add namespace support
9+
thanks to Mark Wu
10+
* Add instruction to enable phar extension in README
11+
112
Version 0.4.2
213
-------------
314

PHPCtags.class.php

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
<?php
22
class 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

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ should be easy though (Apologize for not being able to provide any help for
2525
this, I am really not a Windows guy), it also would be great if someone could
2626
provide a patch for this.
2727

28-
Installation is simple, just run `make` in the root directory of the source,
29-
you will get a `phpctags` PHAR executable, add it to your `$PATH`, then you
30-
can invoke `phpcatgs` directly from anywhere.
28+
Installation is simple, make sure you have PHP's PHAR extension enabled, then
29+
just run `make` in the root directory of the source, you will get a `phpctags`
30+
PHAR executable, add it to your `$PATH`, then you can invoke `phpcatgs`
31+
directly from anywhere.
3132

3233
See [phpctags on packagist](http://packagist.org/packages/techlivezheng/phpctags)
3334
for more details.

bootstrap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@
142142
if (!isset($options['memory']))
143143
$options['memory'] = '128M';
144144
if (!isset($options['fields'])) {
145-
$options['fields'] = array('n', 'k', 's', 'a');
145+
$options['fields'] = array('n', 'k', 's', 'a','i');
146146
} else {
147147
$options['fields'] = str_split($options['fields']);
148148
}

0 commit comments

Comments
 (0)