Skip to content

Commit 158df35

Browse files
committed
Integrate recursive directory generating into PHPCtags
1 parent d2e784b commit 158df35

File tree

2 files changed

+40
-31
lines changed

2 files changed

+40
-31
lines changed

PHPCtags.class.php

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ private function struct($node, $reset=FALSE, $parent=array())
136136

137137
if (!empty($kind) && !empty($name) && !empty($line)) {
138138
$structs[] = array(
139+
'file' => $this->mFile,
139140
'kind' => $kind,
140141
'name' => $name,
141142
'line' => $line,
@@ -154,8 +155,14 @@ private function struct($node, $reset=FALSE, $parent=array())
154155
private function render($structs, $options)
155156
{
156157
$str = '';
157-
$lines = file($this->mFile);
158158
foreach ($structs as $struct) {
159+
$file = $struct['file'];
160+
161+
if (!isset($files[$file]))
162+
$files[$file] = file($file);
163+
164+
$lines = $files[$file];
165+
159166
if (empty($struct['name']) || empty($struct['line']) || empty($struct['kind']))
160167
return;
161168

@@ -165,7 +172,7 @@ private function render($structs, $options)
165172
$str .= $struct['name'];
166173
}
167174

168-
$str .= "\t" . $this->mFile;
175+
$str .= "\t" . $file;
169176

170177
if ($options['excmd'] == 'number') {
171178
$str .= "\t" . $struct['line'];
@@ -225,9 +232,36 @@ private function render($structs, $options)
225232

226233
public function export($file, $options)
227234
{
228-
//@todo Check for existence
229-
$this->mFile = $file;
230-
$structs = $this->struct($this->mParser->parse(file_get_contents($this->mFile)), TRUE);
235+
$structs = array();
236+
if (is_dir($file) && isset($options['R'])) {
237+
$iterator = new RecursiveIteratorIterator(
238+
new RecursiveDirectoryIterator(
239+
$file,
240+
FilesystemIterator::SKIP_DOTS |
241+
FilesystemIterator::FOLLOW_SYMLINKS
242+
)
243+
);
244+
245+
$extensions = array('.php', '.php3', '.php4', '.php5', '.phps');
246+
247+
foreach ($iterator as $filename) {
248+
if (!in_array(substr($filename, strrpos($filename, '.')), $extensions)) {
249+
continue;
250+
}
251+
252+
if (isset($options['exclude']) && false !== strpos($filename, $options['exclude'])) {
253+
continue;
254+
}
255+
256+
//@todo Check for existence
257+
$this->mFile = (string) $filename;
258+
$structs += $this->struct($this->mParser->parse(file_get_contents($this->mFile)), TRUE);
259+
}
260+
} else {
261+
//@todo Check for existence
262+
$this->mFile = $file;
263+
$structs += $this->struct($this->mParser->parse(file_get_contents($this->mFile)), TRUE);
264+
}
231265
return $this->render($structs, $options);
232266
}
233267
}

phpctags

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -78,32 +78,7 @@ if(isset($options['recurse'])) {
7878
}
7979

8080
$ctags = new PHPCtags();
81-
$result = '';
82-
if (is_dir($file) && isset($options['R'])) {
83-
$iterator = new RecursiveIteratorIterator(
84-
new RecursiveDirectoryIterator(
85-
$file,
86-
FilesystemIterator::SKIP_DOTS |
87-
FilesystemIterator::FOLLOW_SYMLINKS
88-
)
89-
);
90-
91-
$extensions = array('.php', '.php3', '.php4', '.php5', '.phps');
92-
93-
foreach ($iterator as $filename) {
94-
if (!in_array(substr($filename, strrpos($filename, '.')), $extensions)) {
95-
continue;
96-
}
97-
98-
if (isset($options['exclude']) && false !== strpos($filename, $options['exclude'])) {
99-
continue;
100-
}
101-
102-
$result .= $ctags->export($filename, $options);
103-
}
104-
} else {
105-
$result = $ctags->export($file, $options);
106-
}
81+
$result = $ctags->export($file, $options);
10782

10883
if (isset($options['f']) && $options['f'] !== '-') {
10984
$tagfile = fopen($options['f'], isset($options['a']) ? 'a' : 'w');

0 commit comments

Comments
 (0)