BaseValidate.php
856 字节
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
namespace app\api\validate;
use think\exception\ValidateException;
use think\Request;
use think\Validate;
class BaseValidate extends Validate{
protected $request;
public function __construct(array $rules = [], $message = [], $field = [])
{
parent::__construct($rules, $message, $field);
$this->request = Request::instance();
}
/**
*检查返回的参数是否正确
* @param $scene 验证场景
* @return mixed
*/
public function goCheck($scene = ''){
$params = $this->request->param();
if($scene) {
$result = $this->scene($scene)->check($params);
} else {
$result = $this->check($params);
}
if(!$result){
throw new ValidateException($this->error);
}else{
return $params;
}
}
}