<?php
declare (strict_types = 1);
namespace app;
use think\App;
use think\exception\ValidateException;
use think\Validate;
use app\middleware\Online;
abstract class BaseController
{
protected $request;
protected $app;
protected $batchValidate = false;
protected $middleware = [
'online'
];
public function __construct(App $app)
{
$this->app = $app;
$this->request = $this->app->request;
$this->view = $this->app->view;
$this->initialize();
}
protected function initialize()
{
}
protected function validate(array $data, $validate, array $message = [], bool $batch = false)
{
if (is_array($validate)) {
$v = new Validate();
$v->rule($validate);
} else {
if (strpos($validate, '.')) {
list($validate, $scene) = explode('.', $validate);
}
$class = false !== strpos($validate, '\\') ? $validate : $this->app->parseClass('validate', $validate);
$v = new $class();
if (!empty($scene)) {
$v->scene($scene);
}
}
$v->message($message);
if ($batch || $this->batchValidate) {
$v->batch(true);
}
return $v->failException(true)->check($data);
}
use \liliuwei\think\Jump;
}