modified 完善中间件

This commit is contained in:
zhaoxiang 2020-10-13 00:44:24 +08:00
parent 9beef9477b
commit 34dd90c82d
9 changed files with 20 additions and 14 deletions

View File

@ -177,9 +177,9 @@ class InterfaceList extends Base {
* @author zhaoxiang <zhaoxiang051405@gmail.com> * @author zhaoxiang <zhaoxiang051405@gmail.com>
*/ */
public function refresh(): Response { public function refresh(): Response {
$rootPath = Env::get('root_path'); $rootPath = root_path();
$apiRoutePath = $rootPath . 'route/apiRoute.php'; $apiRoutePath = $rootPath . 'route/apiRoute.php';
$tplPath = $rootPath . 'application/install/apiRoute.tpl'; $tplPath = $rootPath . 'install/apiRoute.tpl';
$methodArr = ['*', 'POST', 'GET']; $methodArr = ['*', 'POST', 'GET'];
$tplOriginStr = file_get_contents($tplPath); $tplOriginStr = file_get_contents($tplPath);
@ -187,9 +187,9 @@ class InterfaceList extends Base {
$tplStr = []; $tplStr = [];
foreach ($listInfo as $value) { foreach ($listInfo as $value) {
if ($value['hash_type'] === 1) { if ($value['hash_type'] === 1) {
array_push($tplStr, 'Route::rule(\'' . addslashes($value->api_class) . '\',\'api/' . addslashes($value->api_class) . '\', \'' . $methodArr[$value->method] . '\')->middleware([\'ApiAuth\', \'ApiPermission\', \'RequestFilter\', \'ApiLog\']);'); array_push($tplStr, 'Route::rule(\'' . addslashes($value->api_class) . '\',\'api.' . addslashes($value->api_class) . '\', \'' . $methodArr[$value->method] . '\')->middleware([app\middleware\ApiAuth::class, app\middleware\ApiPermission::class, app\middleware\RequestFilter::class, app\middleware\ApiLog::class]);');
} else { } else {
array_push($tplStr, 'Route::rule(\'' . addslashes($value->hash) . '\',\'api/' . addslashes($value->api_class) . '\', \'' . $methodArr[$value->method] . '\')->middleware([\'ApiAuth\', \'ApiPermission\', \'RequestFilter\', \'ApiLog\']);'); array_push($tplStr, 'Route::rule(\'' . addslashes($value->hash) . '\',\'api.' . addslashes($value->api_class) . '\', \'' . $methodArr[$value->method] . '\')->middleware([app\middleware\ApiAuth::class, app\middleware\ApiPermission::class, app\middleware\RequestFilter::class, app\middleware\ApiLog::class]);');
} }
} }
$tplOriginStr = str_replace(['{$API_RULE}'], [implode($tplStr, PHP_EOL . ' ')], $tplOriginStr); $tplOriginStr = str_replace(['{$API_RULE}'], [implode($tplStr, PHP_EOL . ' ')], $tplOriginStr);

View File

@ -1,6 +1,7 @@
<?php <?php
declare (strict_types=1);
namespace app\http\middleware; namespace app\middleware;
use app\model\AdminApp; use app\model\AdminApp;
use app\model\AdminList; use app\model\AdminList;

View File

@ -1,6 +1,7 @@
<?php <?php
declare (strict_types=1);
namespace app\http\middleware; namespace app\middleware;
use app\util\ApiLogTool; use app\util\ApiLogTool;

View File

@ -1,6 +1,7 @@
<?php <?php
declare (strict_types=1);
namespace app\http\middleware; namespace app\middleware;
use app\util\ReturnCode; use app\util\ReturnCode;

View File

@ -1,6 +1,7 @@
<?php <?php
declare (strict_types=1);
namespace app\http\middleware; namespace app\middleware;
use think\facade\Config; use think\facade\Config;

View File

@ -1,6 +1,7 @@
<?php <?php
declare (strict_types=1);
namespace app\http\middleware; namespace app\middleware;
use app\model\AdminFields; use app\model\AdminFields;
use app\util\DataType; use app\util\DataType;

View File

@ -1,6 +1,7 @@
<?php <?php
declare (strict_types=1);
namespace app\http\middleware; namespace app\middleware;
use app\util\ReturnCode; use app\util\ReturnCode;

View File

@ -14,5 +14,5 @@ use think\facade\Route;
Route::group('api', function() { Route::group('api', function() {
{$API_RULE} {$API_RULE}
//MISS路由定义 //MISS路由定义
Route::miss('api/Miss/index'); Route::miss('api.Miss/index');
})->middleware('ApiResponse'); })->middleware(app\middleware\ApiResponse::class);

View File

@ -7,5 +7,5 @@ use think\facade\Route;
Route::group('api', function() { Route::group('api', function() {
//MISS路由定义 //MISS路由定义
Route::miss('api/Miss/index'); Route::miss('api.Miss/index');
})->middleware('ApiResponse'); })->middleware(app\middleware\ApiResponse::class);