优化扩展功能
This commit is contained in:
@@ -101,4 +101,63 @@ class Client extends Base {
|
||||
return $this->error('删除失败!');
|
||||
}
|
||||
}
|
||||
|
||||
public function api(){
|
||||
$list = [];
|
||||
$path = app()->getAppPath() . 'controller/api';
|
||||
|
||||
$classname = $this->scanFile($path);
|
||||
foreach ($classname as $value) {
|
||||
if($value == 'Base'){
|
||||
continue;
|
||||
}
|
||||
$class = "app\\controller\\api\\" . $value;
|
||||
if (class_exists($class)) {
|
||||
$reflection = new \ReflectionClass($class);
|
||||
$group_doc = $this->Parser($reflection->getDocComment());
|
||||
$method = $reflection->getMethods(\ReflectionMethod::IS_FINAL | \ReflectionMethod::IS_PUBLIC);
|
||||
$group_doc['name'] = $value;
|
||||
foreach ($method as $key => $v) {
|
||||
if (!in_array($v->name, ['__construct'])) {
|
||||
$title_doc = $this->Parser($v->getDocComment());
|
||||
if (isset($title_doc['title']) && $title_doc['title']) {
|
||||
$list[] = array(
|
||||
'url' => 'api/' . strtolower($value) . '/' . strtolower($v->name),
|
||||
'name' => 'api/' . strtolower($value) . '/' . strtolower($v->name),
|
||||
'method' => isset($title_doc['method']) ? strtoupper($title_doc['method']) : 'GET',
|
||||
'title' => trim($title_doc['title']),
|
||||
'group' => $group_doc['title'],
|
||||
'status' => 1,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->data = [
|
||||
'list' => $list
|
||||
];
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
protected function scanFile($path) {
|
||||
$result = array();
|
||||
$files = scandir($path);
|
||||
foreach ($files as $file) {
|
||||
if ($file != '.' && $file != '..') {
|
||||
if (is_dir($path . '/' . $file)) {
|
||||
$this->scanFile($path . '/' . $file);
|
||||
} else {
|
||||
$result[] = substr(basename($file), 0, -4);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function Parser($text) {
|
||||
$doc = new \doc\Doc();
|
||||
return $doc->parse($text);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user