用户管理
This commit is contained in:
42
extend/catcher/base/CatchRequest.php
Normal file
42
extend/catcher/base/CatchRequest.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
namespace catcher\base;
|
||||
|
||||
use app\Request;
|
||||
use catcher\exceptions\ValidateFailedException;
|
||||
use think\Validate;
|
||||
|
||||
abstract class BaseRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Request constructor.
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->validate();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化验证
|
||||
*
|
||||
* @time 2019年11月27日
|
||||
* @throws \Exception
|
||||
* @return mixed
|
||||
*/
|
||||
protected function validate()
|
||||
{
|
||||
$validate = new Validate();
|
||||
|
||||
if (!$validate->check(request()->param(), $this->rules())) {
|
||||
throw new ValidateFailedException($validate->getError());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
abstract protected function rules(): array;
|
||||
|
||||
abstract protected function message(): array;
|
||||
}
|
Reference in New Issue
Block a user