Skip to content

Commit 84c0c62

Browse files
committed
Merge branch 'feature/improved-console-support' into develop
Fix #9
2 parents a846888 + 9bb43b8 commit 84c0c62

File tree

3 files changed

+67
-5
lines changed

3 files changed

+67
-5
lines changed

PHPCtags.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ public function export($file, $options)
235235
//@todo Check for existence
236236
$this->mFile = $file;
237237
$structs = $this->struct($this->mParser->parse(file_get_contents($this->mFile)), TRUE);
238-
echo $this->render($structs, $options);
238+
return $this->render($structs, $options);
239239
}
240240

241241
private static function isMemoryLimitValid($memory_limit) {

phpctags

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/php -q
1+
#!/usr/bin/env php
22
<?php
33
if (file_exists($autoload = __DIR__ . '/vendor/autoload.php')) {
44
require($autoload);
@@ -12,11 +12,14 @@ if (file_exists($autoload = __DIR__ . '/vendor/autoload.php')) {
1212
);
1313
}
1414

15-
$options = getopt('f:',array(
15+
$options = getopt('af:R',array(
16+
'append::',
1617
'debug',
18+
'exclude:',
1719
'excmd::',
1820
'fields::',
1921
'format::',
22+
'recurse::',
2023
'version',
2124
'memory::',
2225
));
@@ -50,5 +53,64 @@ if(!isset($options['fields'])) {
5053
$options['fields'] = str_split($options['fields']);
5154
}
5255

56+
if(isset($options['append'])) {
57+
if ($options['append'] === FALSE || yes_or_no($options['append']) == 'yes') {
58+
$options['a'] = FALSE;
59+
} else if (yes_or_no($options['append']) != 'no') {
60+
die('phpctags: Invalid value for "append" option');
61+
}
62+
}
63+
64+
if(isset($options['recurse'])) {
65+
if ($options['recurse'] === FALSE || yes_or_no($options['recurse']) == 'yes') {
66+
$options['R'] = FALSE;
67+
} else if (yes_or_no($options['recurse']) != 'no') {
68+
die('phpctags: Invalid value for "recurse" option');
69+
}
70+
}
71+
5372
$ctags = new PHPCtags();
54-
$ctags->export($file, $options);
73+
$result = '';
74+
if (isset($options['R'])) {
75+
$iterator = new RecursiveIteratorIterator(
76+
new RecursiveDirectoryIterator(
77+
$file,
78+
FilesystemIterator::SKIP_DOTS |
79+
FilesystemIterator::FOLLOW_SYMLINKS
80+
)
81+
);
82+
83+
$extensions = array('.php', '.php3', '.php4', '.php5', '.phps');
84+
85+
foreach ($iterator as $filename) {
86+
if (!in_array(substr($filename, strrpos($filename, '.')), $extensions)) {
87+
continue;
88+
}
89+
90+
if (isset($options['exclude']) && false !== strpos($filename, $options['exclude'])) {
91+
continue;
92+
}
93+
94+
$result .= $ctags->export($filename, $options);
95+
}
96+
} else {
97+
$result = $ctags->export($file, $options);
98+
}
99+
100+
if (isset($options['f']) && $options['f'] !== '-') {
101+
$tagfile = fopen($options['f'], isset($options['a']) ? 'a' : 'w');
102+
} else {
103+
$tagfile = fopen('php://stdout', 'w');
104+
}
105+
fwrite($tagfile, $result);
106+
fclose($tagfile);
107+
108+
function yes_or_no($arg) {
109+
if (preg_match('/\b[Y|y]([E|e][S|s])?\b/', $arg)) {
110+
return 'yes';
111+
} else if (preg_match('/\b[N|n]([O|o])?\b/', $arg)) {
112+
return 'no';
113+
} else {
114+
return false;
115+
}
116+
}

tests/PHPCtagsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function testExport($testcase)
6161
ob_start();
6262
$testcase_example = $testcase_object->getExample();
6363
$testcase_options = $testcase_object->getOptions();
64-
$this->object->export($testcase_example, $testcase_options);
64+
echo $this->object->export($testcase_example, $testcase_options);
6565
$testcase_result = ob_get_contents();
6666
ob_end_clean();
6767

0 commit comments

Comments
 (0)