Skip to content

Commit 8f2f454

Browse files
committed
Add support for generating mutiple files
1 parent 94efe53 commit 8f2f454

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

PHPCtags.class.php

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ class PHPCtags
33
{
44
private $mFile;
55

6+
private $mFiles;
7+
68
private static $mKinds = array(
79
'c' => 'class',
810
'm' => 'method',
@@ -48,6 +50,18 @@ public static function getMKinds()
4850
return self::$mKinds;
4951
}
5052

53+
public function addFile($file)
54+
{
55+
$this->mFiles[realpath($file)] = 1;
56+
}
57+
58+
public function addFiles($files)
59+
{
60+
foreach ($files as $file) {
61+
$this->addFile($file);
62+
}
63+
}
64+
5165
private function getNodeAccess($node)
5266
{
5367
if ($node->isPrivate()) return 'private';
@@ -294,7 +308,20 @@ private function render()
294308
return $str;
295309
}
296310

297-
public function export($file)
311+
public function export()
312+
{
313+
if (empty($this->mFiles)) {
314+
throw new PHPCtagsException('No File specified.');
315+
}
316+
317+
foreach (array_keys($this->mFiles) as $file) {
318+
$this->process($file);
319+
}
320+
321+
return $this->render();
322+
}
323+
324+
private function process($file)
298325
{
299326
if (is_dir($file) && isset($this->mOptions['R'])) {
300327
$iterator = new RecursiveIteratorIterator(
@@ -329,7 +356,6 @@ public function export($file)
329356
$this->struct($this->mParser->parse(file_get_contents($this->mFile)), TRUE)
330357
);
331358
}
332-
return $this->render();
333359
}
334360
}
335361

phpctags

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ EOF;
5959

6060
array_shift($argv);
6161

62-
$file = array_pop($argv);
63-
6462
// option -o is an alternative to -f
6563
if (isset($options['o']) && !isset($options['f'])) {
6664
$options['f'] = $options['o'];
@@ -145,7 +143,8 @@ if (isset($options['recurse'])) {
145143

146144
try {
147145
$ctags = new PHPCtags($options);
148-
$result = $ctags->export($file);
146+
$ctags->addFiles($argv);
147+
$result = $ctags->export();
149148
} catch (Exception $e) {
150149
die("phpctags: {$e->getMessage()}");
151150
}

tests/PHPCtagsTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,10 @@ public function testExport($testcase)
5959
$phpctags_object = new PHPCtags(
6060
$testcase_object->getOptions()
6161
);
62-
$testcase_result = $phpctags_object->export(
62+
$phpctags_object->addFile(
6363
$testcase_object->getExample()
6464
);
65+
$testcase_result = $phpctags_object->export();
6566

6667
$expected_result = __DIR__ . '/' . $testcase_id . '.testcase.expect';
6768
$acctural_result = __DIR__ . '/' . $testcase_id . '.testcase.result';

0 commit comments

Comments
 (0)