在
Windows平台上或者如果您想使用
PHP本身,您可以使用…
function getTodos($path) {
$todos = array();
$items = glob(rtrim($path, '/') . '/*');
foreach($items as $item) {
if (is_file($item) AND pathinfo($item, PATHINFO_EXTENSION) == 'php') {
$fileContents = file_get_contents($item);
$tokens = token_get_all($fileContents);
foreach($tokens as $type = $token) {
if (($type == 'T_COMMENT' OR $type == 'T_ML_COMMENT')
AND preg_match_all('/^\s*(?P@todo.*?)\z/m', $token, $matches) {
$todos = array_merge($todos, $matches['todo']);
}
}
} else if (is_dir($item)) {
$todos = array_merge$($todos, getTodos($item));
continue;
}
}
return $lines;
}
我没有测试它,但它应该在理论上工作. 🙂
在* nix上,你可以使用grep …
$grep -r \b@todo\b ./
它并不完美(它会在字符串中找到它)但它应该足够好. 🙂