catchAdmin/extend/catcher/base/CatchRequest.php

44 lines
881 B
PHP
Raw Normal View History

2019-12-06 09:17:40 +08:00
<?php
namespace catcher\base;
use app\Request;
2019-12-15 13:38:25 +08:00
use catcher\exceptions\FailedException;
2019-12-06 09:17:40 +08:00
use catcher\exceptions\ValidateFailedException;
use think\Validate;
2019-12-13 17:26:54 +08:00
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()
{
2019-12-15 13:38:25 +08:00
try {
$validate = new Validate();
2019-12-06 09:17:40 +08:00
2019-12-15 13:38:25 +08:00
if (!$validate->check(request()->param(), $this->rules())) {
throw new FailedException($validate->getError());
}
} catch (\Exception $e) {
throw new ValidateFailedException($e->getMessage());
2019-12-06 09:17:40 +08:00
}
return true;
}
}