catchAdmin/extend/catcher/base/CatchRequest.php

43 lines
819 B
PHP
Raw Normal View History

2019-12-06 09:17:40 +08:00
<?php
namespace catcher\base;
use app\Request;
use catcher\exceptions\ValidateFailedException;
use think\Validate;
2019-12-12 09:14:08 +08:00
abstract class CatchRequest extends Request
2019-12-06 09:17:40 +08:00
{
/**
* 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;
}