// 這是一個獲取類方法和註釋的方法 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); }