mirror of
https://gitee.com/apiadmin/ApiAdmin.git
synced 2025-04-06 03:58:00 +08:00
modified 因为PHP不是强数据类型,考虑到框架的通用,不再过滤请求数据
This commit is contained in:
parent
7d58967b96
commit
d88b571fc3
@ -7,13 +7,12 @@ use app\util\DataType;
|
|||||||
use app\util\ReturnCode;
|
use app\util\ReturnCode;
|
||||||
use think\facade\Cache;
|
use think\facade\Cache;
|
||||||
use think\facade\Validate;
|
use think\facade\Validate;
|
||||||
use think\Request as re;
|
|
||||||
|
|
||||||
|
|
||||||
class RequestFilter {
|
class RequestFilter {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 接口请求字段过滤
|
* 接口请求字段过滤【只验证数据的合法性,不再过滤数据】
|
||||||
* @param \think\facade\Request $request
|
* @param \think\facade\Request $request
|
||||||
* @param \Closure $next
|
* @param \Closure $next
|
||||||
* @return mixed|\think\response\Json
|
* @return mixed|\think\response\Json
|
||||||
@ -22,17 +21,14 @@ class RequestFilter {
|
|||||||
public function handle($request, \Closure $next) {
|
public function handle($request, \Closure $next) {
|
||||||
$apiInfo = $request->API_CONF_DETAIL;
|
$apiInfo = $request->API_CONF_DETAIL;
|
||||||
$data = $request->param();
|
$data = $request->param();
|
||||||
$method = $request->method();
|
|
||||||
|
|
||||||
$has = Cache::has('RequestFields:NewRule:' . $apiInfo['hash']);
|
$has = Cache::has('RequestFields:NewRule:' . $apiInfo['hash']);
|
||||||
if ($has) {
|
if ($has) {
|
||||||
$newRule = cache('RequestFields:NewRule:' . $apiInfo['hash']);
|
$newRule = cache('RequestFields:NewRule:' . $apiInfo['hash']);
|
||||||
$rule = cache('RequestFields:Rule:' . $apiInfo['hash']);
|
|
||||||
} else {
|
} else {
|
||||||
$rule = AdminFields::all(['hash' => $apiInfo['hash'], 'type' => 0]);
|
$rule = AdminFields::all(['hash' => $apiInfo['hash'], 'type' => 0]);
|
||||||
$newRule = $this->buildValidateRule($rule);
|
$newRule = $this->buildValidateRule($rule);
|
||||||
cache('RequestFields:NewRule:' . $apiInfo['hash'], $newRule);
|
cache('RequestFields:NewRule:' . $apiInfo['hash'], $newRule);
|
||||||
cache('RequestFields:Rule:' . $apiInfo['hash'], $rule);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($newRule) {
|
if ($newRule) {
|
||||||
@ -42,30 +38,6 @@ class RequestFilter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$newData = [];
|
|
||||||
foreach ($rule as $item) {
|
|
||||||
$newData[$item['field_name']] = isset($data[$item['field_name']]) ? $data[$item['field_name']] : '';
|
|
||||||
if (!$item['is_must'] && $item['default'] !== '' && !isset($data[$item['field_name']])) {
|
|
||||||
$newData[$item['field_name']] = $item['default'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO::等待研究没有测试通过
|
|
||||||
*/
|
|
||||||
switch ($method) {
|
|
||||||
case 'GET':
|
|
||||||
(new re())->withGet($newData);
|
|
||||||
break;
|
|
||||||
case 'POST':
|
|
||||||
(new re())->withPost($newData);
|
|
||||||
break;
|
|
||||||
case 'DELETE':
|
|
||||||
case 'PUT':
|
|
||||||
(new re())->withInput($newData);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $next($request);
|
return $next($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user