mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 12:42:48 +08:00
Controller类增加batchValidate属性 validate方法增加batch参数,用于设置是否批量验证
异常类改进
This commit is contained in:
@@ -28,6 +28,8 @@ class Controller
|
||||
protected $request;
|
||||
// 验证失败是否抛出异常
|
||||
protected $failException = false;
|
||||
// 是否批量验证
|
||||
protected $batchValidate = false;
|
||||
|
||||
/**
|
||||
* 前置操作方法列表
|
||||
@@ -162,10 +164,11 @@ class Controller
|
||||
* @param array $data 数据
|
||||
* @param string|array $validate 验证器名或者验证规则数组
|
||||
* @param array $message 提示信息
|
||||
* @param bool $batch 是否批量验证
|
||||
* @param mixed $callback 回调方法(闭包)
|
||||
* @return true|string|array
|
||||
*/
|
||||
protected function validate($data, $validate, $message = [], $callback = null)
|
||||
protected function validate($data, $validate, $message = [], $batch = false, $callback = null)
|
||||
{
|
||||
if (is_array($validate)) {
|
||||
$v = Loader::validate();
|
||||
@@ -180,12 +183,16 @@ class Controller
|
||||
$v->scene($scene);
|
||||
}
|
||||
}
|
||||
// 是否批量验证
|
||||
if($batch || $this->batchValidate){
|
||||
$v->batch(true);
|
||||
}
|
||||
|
||||
if (is_array($message)) {
|
||||
$v->message($message);
|
||||
}
|
||||
|
||||
if (is_callable($callback)) {
|
||||
if ($callback && is_callable($callback)) {
|
||||
call_user_func_array($callback, [$v, &$data]);
|
||||
}
|
||||
|
||||
|
||||
@@ -291,7 +291,7 @@ class Loader
|
||||
if (class_exists($class)) {
|
||||
$model = new $class();
|
||||
} else {
|
||||
throw new ClassNotFoundException('class [ ' . $class . ' ] not exists');
|
||||
throw new ClassNotFoundException('class [ ' . $class . ' ] not exists', $class);
|
||||
}
|
||||
}
|
||||
$_model[$name . $layer] = $model;
|
||||
@@ -327,7 +327,7 @@ class Loader
|
||||
} elseif ($empty && class_exists($emptyClass = self::parseClass($module, $layer, $empty, $appendSuffix))) {
|
||||
return new $emptyClass(Request::instance());
|
||||
} else {
|
||||
throw new ClassNotFoundException('class [ ' . $class . ' ] not exists');
|
||||
throw new ClassNotFoundException('class [ ' . $class . ' ] not exists', $class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -364,7 +364,7 @@ class Loader
|
||||
if (class_exists($class)) {
|
||||
$validate = new $class;
|
||||
} else {
|
||||
throw new ClassNotFoundException('class [ ' . $class . ' ] not exists');
|
||||
throw new ClassNotFoundException('class [ ' . $class . ' ] not exists', $class);
|
||||
}
|
||||
}
|
||||
$_instance[$name . $layer] = $validate;
|
||||
@@ -428,7 +428,7 @@ class Loader
|
||||
$_instance[$identify] = $o;
|
||||
}
|
||||
} else {
|
||||
throw new ClassNotFoundException('class not exist :' . $class);
|
||||
throw new ClassNotFoundException('class not exist :' . $class, $class);
|
||||
}
|
||||
}
|
||||
return $_instance[$identify];
|
||||
|
||||
@@ -94,7 +94,7 @@ class Session
|
||||
|
||||
// 检查驱动类
|
||||
if (!class_exists($class) || !session_set_save_handler(new $class($config))) {
|
||||
throw new ClassNotFoundException('error session handler');
|
||||
throw new ClassNotFoundException('error session handler', $class);
|
||||
}
|
||||
}
|
||||
if ($isDoStart) {
|
||||
|
||||
@@ -1068,7 +1068,7 @@ class Template
|
||||
$this->includeFile[$template] = filemtime($template);
|
||||
return $template;
|
||||
} else {
|
||||
throw new TemplateNotFoundException('template not exist:' . $template);
|
||||
throw new TemplateNotFoundException('template not exist:' . $template, $template);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1723,7 +1723,11 @@ class Query
|
||||
}
|
||||
}
|
||||
} elseif (!empty($options['fail'])) {
|
||||
throw new DbException('Data not Found', $options, $sql);
|
||||
if(!empty($this->model)){
|
||||
throw new ModelNotFoundException('Data not Found', $this->model, $options);
|
||||
}else{
|
||||
throw new DataNotFoundException('Data not Found', $options['table'], $options);
|
||||
}
|
||||
}
|
||||
return $resultSet;
|
||||
}
|
||||
|
||||
@@ -31,5 +31,13 @@ class DataNotFoundException extends DbException
|
||||
$this->setData('Database Config', $config);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取数据表名
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getTable()
|
||||
{
|
||||
return $this->table;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,11 @@ class ModelNotFoundException extends DbException
|
||||
$this->setData('Database Config', $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取模型类名
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getModel()
|
||||
{
|
||||
return $this->model;
|
||||
|
||||
@@ -13,4 +13,20 @@ namespace think\exception;
|
||||
|
||||
class ClassNotFoundException extends \RuntimeException
|
||||
{
|
||||
protected $class;
|
||||
public function __construct($message,$class='')
|
||||
{
|
||||
$this->message = $message;
|
||||
$this->class = $class;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取类名
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getClass()
|
||||
{
|
||||
return $this->class;
|
||||
}
|
||||
}
|
||||
@@ -13,4 +13,21 @@ namespace think\exception;
|
||||
|
||||
class TemplateNotFoundException extends \RuntimeException
|
||||
{
|
||||
protected $template;
|
||||
|
||||
public function __construct($message,$template='')
|
||||
{
|
||||
$this->message = $message;
|
||||
$this->template = $template;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取模板文件
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getTemplate()
|
||||
{
|
||||
return $this->template;
|
||||
}
|
||||
}
|
||||
@@ -13,4 +13,20 @@ namespace think\exception;
|
||||
|
||||
class ValidateException extends \RuntimeException
|
||||
{
|
||||
protected $error;
|
||||
|
||||
public function __construct($error)
|
||||
{
|
||||
$this->error = $error;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取验证错误信息
|
||||
* @access public
|
||||
* @return array|string
|
||||
*/
|
||||
public function getError()
|
||||
{
|
||||
return $this->error;
|
||||
}
|
||||
}
|
||||
@@ -62,7 +62,7 @@ class Php
|
||||
}
|
||||
// 模板不存在 抛出异常
|
||||
if (!is_file($template)) {
|
||||
throw new TemplateNotFoundException('template file not exists:' . $template);
|
||||
throw new TemplateNotFoundException('template file not exists:' . $template, $template);
|
||||
}
|
||||
// 记录视图信息
|
||||
APP_DEBUG && Log::record('[ VIEW ] ' . $template . ' [ ' . var_export(array_keys($data), true) . ' ]', 'info');
|
||||
|
||||
@@ -72,7 +72,7 @@ class Think
|
||||
}
|
||||
// 模板不存在 抛出异常
|
||||
if (!is_file($template)) {
|
||||
throw new TemplateNotFoundException('template file not exists:' . $template);
|
||||
throw new TemplateNotFoundException('template file not exists:' . $template, $template);
|
||||
}
|
||||
// 记录视图信息
|
||||
APP_DEBUG && Log::record('[ VIEW ] ' . $template . ' [ ' . var_export(array_keys($data), true) . ' ]', 'info');
|
||||
|
||||
Reference in New Issue
Block a user