BaseValidate.php
698 字节
<?php
namespace app\api\validate;
use app\api\exception\ApiExceptionCustom;
use think\Validate;
use think\Exception;
use think\Request;
class BaseValidate extends Validate
{
public function goCheck($data='')
{
//实例化请求对象
$requestObj=Request::instance();
//如果传入为空则获取请求里的参数
empty($data)&&$data=$requestObj->param();
if ($this->check($data)) {
//如果验证通过了
return true;
}else{
//如果验证没通过
$error=$this->getError();
//抛出异常
(new ApiExceptionCustom())->throw_api_exception($error);
}
}
}