获取类方法和注释
// 这是一个获取类方法和注释的方法
public function generateMethod()
{
$r = new \ReflectionClass('\think\Build');
$methods = $r->getMethods();
$string = '';
foreach ($methods as $m) {
$limit = 'public';
if ($m->isPrivate()) {
$limit = 'private';
} elseif ($m->isProtected()) {
$limit = 'protected';
}
$methodDefinition = '### ' . $limit . ' function ' . $m->getName() . '(';
$methodParam = $m->getParameters();
foreach ($methodParam as $mp) {
$type = '';
if ($mp->hasType()) {
$type = $mp->getType()->getName() . ' ';
}
$name = $mp->getName();
$value = '';
if ($mp->isDefaultValueAvailable()) {
$defaultValue = $mp->getDefaultValue();
if (is_array($defaultValue)) {
$value = ' = []';
} elseif (is_bool($defaultValue)) {
$value = $defaultValue ? ' = true ' : ' = false ';
} else {
$value = ' = \'' . $mp->getDefaultValue() . '\'';
}
}
$methodDefinition .= $type . '$' . $name . $value . ',';
}
$methodDefinition = rtrim($methodDefinition, ',');
$methodDefinition .= ')';
$methodDefinition .= PHP_EOL;
$methodDefinition .= "\t" . str_replace(['/', '*', '/'], '', $m->getDocComment());
$methodDefinition .= PHP_EOL;
$methodDefinition .= PHP_EOL;
$string .= $methodDefinition;
}
file_put_contents('./classMethodList.txt', $string);
}
只言片语任我说,提笔句句无需忖。落笔不知寄何人,唯有邀友共斟酌。