From 279d8d876fb60e7752e3b2199f578762cb4a5558 Mon Sep 17 00:00:00 2001 From: Karson Date: Thu, 28 Nov 2024 11:46:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96API=E6=96=87=E6=A1=A3?= =?UTF-8?q?=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/command/Api.php | 14 ++++++++++---- application/admin/command/Api/library/Builder.php | 12 ++++++------ application/admin/command/Api/template/index.html | 4 ++-- application/api/controller/Common.php | 2 +- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/application/admin/command/Api.php b/application/admin/command/Api.php index caff52b4..925cb977 100644 --- a/application/admin/command/Api.php +++ b/application/admin/command/Api.php @@ -98,13 +98,19 @@ class Api extends Command foreach ($files as $name => $file) { if (!$file->isDir() && $file->getExtension() == 'php') { $filePath = $file->getRealPath(); - $classes[] = $this->getClassFromFile($filePath); + $className = $this->getClassFromFile($filePath); + if ($className) { + $classes[] = $className; + } } } } else { foreach ($controller as $index => $item) { $filePath = $moduleDir . Config::get('url_controller_layer') . DS . $item . '.php'; - $classes[] = $this->getClassFromFile($filePath); + $className = $this->getClassFromFile($filePath); + if ($className) { + $classes[] = $className; + } } } @@ -183,7 +189,7 @@ class Api extends Command } } } - - return $namespace . '\\' . $class; + $className = $namespace . '\\' . $class; + return preg_match('/([a-z0-9_\\]+)([a-z0-9_]+)$/i', $className) ? $className : ''; } } diff --git a/application/admin/command/Api/library/Builder.php b/application/admin/command/Api/library/Builder.php index 7037378b..1b68d6cd 100755 --- a/application/admin/command/Api/library/Builder.php +++ b/application/admin/command/Api/library/Builder.php @@ -90,14 +90,15 @@ class Builder $typeArr = [ 'integer' => 'number', - 'file' => 'file', + 'file' => 'file', ]; $paramslist = array(); foreach ($docs['ApiParams'] as $params) { - $inputtype = $params['type'] && isset($typeArr[$params['type']]) ? $typeArr[$params['type']] : ($params['name'] == 'password' ? 'password' : 'text'); + $type = strtolower($params['type'] ?? 'string'); + $inputtype = $typeArr[$type] ?? ($params['name'] == 'password' ? 'password' : 'text'); $tr = array( 'name' => $params['name'], - 'type' => $params['type'] ?? 'string', + 'type' => $type, 'inputtype' => $inputtype, 'sample' => $params['sample'] ?? '', 'required' => $params['required'] ?? true, @@ -162,7 +163,7 @@ class Builder 'OPTIONS' => 'label-info' ); - return isset($labes[$method]) ? $labes[$method] : $labes['GET']; + return $labes[$method] ?? $labes['GET']; } public function parse() @@ -230,7 +231,7 @@ class Builder foreach ($docsList as $index => &$methods) { $methodSectorArr = []; foreach ($methods as $name => $method) { - $methodSectorArr[$name] = isset($method['weigh']) ? $method['weigh'] : 0; + $methodSectorArr[$name] = $method['weigh'] ?? 0; } arsort($methodSectorArr); $methods = array_merge(array_flip(array_keys($methodSectorArr)), $methods); @@ -253,7 +254,6 @@ class Builder public function render($template, $vars = []) { $docsList = $this->parse(); - return $this->view->display(file_get_contents($template), array_merge($vars, ['docsList' => $docsList])); } } diff --git a/application/admin/command/Api/template/index.html b/application/admin/command/Api/template/index.html index 365c9291..698e84c2 100755 --- a/application/admin/command/Api/template/index.html +++ b/application/admin/command/Api/template/index.html @@ -154,8 +154,8 @@