Skip to content

Commit 3775941

Browse files
markwuweynhamz
authored andcommitted
Add inherits support, include extends(class) and implements(interface)
1 parent 251d5f0 commit 3775941

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

PHPCtags.class.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ private function struct($node, $reset=FALSE, $parent=array())
111111
$structs = array();
112112
}
113113

114-
$kind = $name = $line = $access = '';
114+
$kind = $name = $line = $access = $extends = '';
115+
$implements = array();
115116

116117
if (!empty($parent)) array_push($scope, $parent);
117118

@@ -122,6 +123,8 @@ private function struct($node, $reset=FALSE, $parent=array())
122123
} elseif ($node instanceof PHPParser_Node_Stmt_Class) {
123124
$kind = 'c';
124125
$name = $node->name;
126+
$extends = $node->extends;
127+
$implements = $node->implements;
125128
$line = $node->getLine();
126129
foreach ($node as $subNode) {
127130
$this->struct($subNode, FALSE, array('class' => $name));
@@ -218,6 +221,8 @@ private function struct($node, $reset=FALSE, $parent=array())
218221
'file' => $this->mFile,
219222
'kind' => $kind,
220223
'name' => $name,
224+
'extends' => $extends,
225+
'implements' => $implements,
221226
'line' => $line,
222227
'scope' => $scope,
223228
'access' => $access,
@@ -298,6 +303,21 @@ private function render()
298303
$str .= "\t" . $scope;
299304
}
300305

306+
#field=i
307+
if(in_array('i', $this->mOptions['fields'])) {
308+
$inherits = array();
309+
if(!empty($struct['extends'])) {
310+
$inherits[] = $struct['extends']->toString();
311+
}
312+
if(!empty($struct['implements'])) {
313+
foreach($struct['implements'] as $interface) {
314+
$inherits[] = $interface->toString();
315+
}
316+
}
317+
if(!empty($inherits))
318+
$str .= "\t" . 'inherits:' . implode(',', $inherits);
319+
}
320+
301321
#field=a
302322
if (in_array('a', $this->mOptions['fields']) && !empty($struct['access'])) {
303323
$str .= "\t" . "access:" . $struct['access'];

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)