1、后台的一些bug修复

2、内核更新
3、后台的扩展模型做了一点更新一点,还不够完善
This commit is contained in:
2016-07-19 14:08:00 +08:00
parent 124745c341
commit 783369c9e4
26 changed files with 492 additions and 238 deletions

View File

@@ -11,7 +11,6 @@
namespace think;
use think\Exception;
use think\Request;
class Validate
@@ -35,51 +34,53 @@ class Validate
// 验证规则默认提示信息
protected static $typeMsg = [
'require' => ':attribute不能为空',
'number' => ':attribute必须是数字',
'float' => ':attribute必须是浮点数',
'boolean' => ':attribute必须是布尔值',
'email' => ':attribute格式不符',
'array' => ':attribute必须是数组',
'accepted' => ':attribute必须是yes、on或者1',
'date' => ':attribute格式不符合',
'file' => ':attribute不是有效的上传文件',
'alpha' => ':attribute只能是字母',
'alphaNum' => ':attribute只能是字母和数字',
'alphaDash' => ':attribute只能是字母数字和下划线_及破折号-',
'activeUrl' => ':attribute不是有效的域名或者IP',
'chs' => ':attribute只能是汉字',
'chsAlpha' => ':attribute只能是汉字、字母',
'chsAlphaNum'=> ':attribute只能是汉字、字母和数字',
'chsDash' => ':attribute只能是汉字、字母数字和下划线_及破折号-',
'url' => ':attribute不是有效的URL地址',
'ip' => ':attribute不是有效的IP地址',
'dateFormat' => ':attribute必须使用日期格式 :rule',
'in' => ':attribute必须 :rule 范围内',
'notIn' => ':attribute不能在 :rule 范围内',
'between' => ':attribute能在 :1 - :2 之间',
'notBetween' => ':attribute能在 :1 - :2 之间',
'length' => ':attribute长度不符合要求 :rule',
'max' => ':attribute长度不能超过 :rule',
'min' => ':attribute长度不能小于 :rule',
'after' => ':attribute日期不能小于 :rule',
'before' => ':attribute日期不能超过 :rule',
'expire' => '不在有效期内 :rule',
'allowIp' => '不允许的IP访问',
'denyIp' => '禁止的IP访问',
'confirm' => ':attribute和字段 :rule 不一致',
'egt' => ':attribute必须大于等于 :rule',
'gt' => ':attribute必须大于 :rule',
'elt' => ':attribute必须小于等于 :rule',
'lt' => ':attribute必须小于 :rule',
'eq' => ':attribute必须于 :rule',
'unique' => ':attribute已存在',
'regex' => ':attribute不符合指定规则',
'method' => '无效的请求类型',
'token' => '令牌数据无效',
'fileSize' => '上传文件大小不符',
'fileExt' => '上传文件后缀不符',
'fileMime' => '上传文件类型不符',
'require' => ':attribute不能为空',
'number' => ':attribute必须是数字',
'float' => ':attribute必须是浮点数',
'boolean' => ':attribute必须是布尔值',
'email' => ':attribute格式不符',
'array' => ':attribute必须是数组',
'accepted' => ':attribute必须是yes、on或者1',
'date' => ':attribute格式不符合',
'file' => ':attribute不是有效的上传文件',
'image' => ':attribute不是有效的图像文件',
'alpha' => ':attribute只能是字母',
'alphaNum' => ':attribute只能是字母数字',
'alphaDash' => ':attribute只能是字母、数字和下划线_及破折号-',
'activeUrl' => ':attribute不是有效的域名或者IP',
'chs' => ':attribute只能是汉字',
'chsAlpha' => ':attribute只能是汉字、字母',
'chsAlphaNum' => ':attribute只能是汉字、字母数字',
'chsDash' => ':attribute只能是汉字、字母、数字和下划线_及破折号-',
'url' => ':attribute不是有效的URL地址',
'ip' => ':attribute不是有效的IP地址',
'dateFormat' => ':attribute必须使用日期格式 :rule',
'in' => ':attribute必须在 :rule 范围内',
'notIn' => ':attribute能在 :rule 范围内',
'between' => ':attribute能在 :1 - :2 之间',
'notBetween' => ':attribute不能在 :1 - :2 之间',
'length' => ':attribute长度不符合要求 :rule',
'max' => ':attribute长度不能超过 :rule',
'min' => ':attribute长度不能小于 :rule',
'after' => ':attribute日期不能小于 :rule',
'before' => ':attribute日期不能超过 :rule',
'expire' => '不在有效期内 :rule',
'allowIp' => '不允许的IP访问',
'denyIp' => '禁止的IP访问',
'confirm' => ':attribute和字段 :rule 不一致',
'egt' => ':attribute必须大于等于 :rule',
'gt' => ':attribute必须于 :rule',
'elt' => ':attribute必须小于等于 :rule',
'lt' => ':attribute必须于 :rule',
'eq' => ':attribute必须等于 :rule',
'unique' => ':attribute已存在',
'regex' => ':attribute不符合指定规则',
'method' => '无效的请求类型',
'token' => '令牌数据无效',
'fileSize' => '上传文件大小不符',
'fileExt' => '上传文件后缀不符',
'fileMime' => '上传文件类型不符',
];
// 当前验证场景
@@ -386,33 +387,6 @@ class Validate
return true !== $result ? $result : true;
}
/**
* 验证表单令牌(需要配置令牌生成行为)
* @access protected
* @param mixed $value 字段值
* @param mixed $rule 验证规则
* @param array $data 数据
* @return bool
*/
protected function token($value, $rule, $data)
{
if (!isset($data[$rule]) || !isset($_SESSION[$rule])) {
// 令牌数据无效
return false;
}
// 令牌验证
list($key, $value) = explode('_', $data[$rule]);
if (isset($_SESSION[$rule][$key]) && $value && $_SESSION[$rule][$key] === $value) {
// 防止重复提交
unset($_SESSION[$rule][$key]); // 验证完成销毁session
return true;
}
// 开启TOKEN重置
unset($_SESSION[$rule][$key]);
return false;
}
/**
* 验证是否和某个字段的值一致
* @access protected
@@ -570,8 +544,10 @@ class Validate
$result = is_array($value);
break;
case 'file':
$file = Request::instance()->file($value);
$result = !empty($file);
$result = $value instanceof \think\File;
break;
case 'image':
$result = $value instanceof \think\File && in_array(exif_imagetype($value->getRealPath()), [1, 2, 3, 6]);
break;
default:
if (isset(self::$type[$rule])) {
@@ -615,14 +591,13 @@ class Validate
/**
* 验证上传文件后缀
* @access protected
* @param mixed $value 字段值
* @param mixed $file 上传文件
* @param mixed $rule 验证规则
* @return bool
*/
protected function fileExt($value, $rule)
protected function fileExt($file, $rule)
{
$file = Request::instance()->file($value);
if (empty($file)) {
if (!($file instanceof \think\File)) {
return false;
}
if (is_string($rule)) {
@@ -630,27 +605,26 @@ class Validate
}
if (is_array($file)) {
foreach ($file as $item) {
if (!in_array(strtolower($item->getExtension()), $rule)) {
if (!$item->checkExt($rule)) {
return false;
}
}
return true;
} else {
return in_array(strtolower($file->getExtension()), $rule);
return $file->checkExt($rule);
}
}
/**
* 验证上传文件类型
* @access protected
* @param mixed $value 字段值
* @param mixed $file 上传文件
* @param mixed $rule 验证规则
* @return bool
*/
protected function fileMime($value, $rule)
protected function fileMime($file, $rule)
{
$file = Request::instance()->file($value);
if (empty($file)) {
if (!($file instanceof \think\File)) {
return false;
}
if (is_string($rule)) {
@@ -658,44 +632,67 @@ class Validate
}
if (is_array($file)) {
foreach ($file as $item) {
if (!in_array(strtolower($item->getMime()), $rule)) {
if (!$item->checkMime($rule)) {
return false;
}
}
return true;
} else {
return in_array(strtolower($file->getMime()), $rule);
return $file->checkMime($rule);
}
}
/**
* 验证上传文件大小
* @access protected
* @param mixed $value 字段值
* @param mixed $file 上传文件
* @param mixed $rule 验证规则
* @return bool
*/
protected function fileSize($value, $rule)
protected function fileSize($file, $rule)
{
$file = Request::instance()->file($value);
if (empty($file)) {
if (!($file instanceof \think\File)) {
return false;
}
if (is_string($rule)) {
$rule = explode(',', $rule);
}
if (is_array($file)) {
foreach ($file as $item) {
if ($item->getSize() > $rule) {
if (!$item->checkSize($rule)) {
return false;
}
}
return true;
} else {
return $file->getSize() <= $rule;
return $file->checkSize($rule);
}
}
/**
* 验证图片的宽高及类型
* @access protected
* @param mixed $file 上传文件
* @param mixed $rule 验证规则
* @return bool
*/
protected function image($file, $rule)
{
if (!($file instanceof \think\File)) {
return false;
}
$rule = explode(',', $rule);
list($width, $height, $type) = getimagesize($file->getRealPath());
if (isset($rule[2])) {
$imageType = strtolower($rule[2]);
if ('jpeg' == $imageType) {
$imageType = 'jpg';
}
if (image_type_to_extension($type) != $imageType) {
return false;
}
}
list($w, $h) = $rule;
return $w == $width && $h == $height;
}
/**
* 验证请求类型
* @access protected
@@ -915,7 +912,14 @@ class Validate
*/
protected function length($value, $rule)
{
$length = strlen((string) $value); // 当前数据长度
if (is_array($value)) {
$length = count($value);
} elseif ($value instanceof \think\File) {
$length = $value->getSize();
} else {
$length = mb_strlen((string) $value);
}
if (strpos($rule, ',')) {
// 长度区间
list($min, $max) = explode(',', $rule);
@@ -935,7 +939,13 @@ class Validate
*/
protected function max($value, $rule)
{
$length = strlen((string) $value);
if (is_array($value)) {
$length = count($value);
} elseif ($value instanceof \think\File) {
$length = $value->getSize();
} else {
$length = mb_strlen((string) $value);
}
return $length <= $rule;
}
@@ -948,7 +958,13 @@ class Validate
*/
protected function min($value, $rule)
{
$length = strlen((string) $value);
if (is_array($value)) {
$length = count($value);
} elseif ($value instanceof \think\File) {
$length = $value->getSize();
} else {
$length = mb_strlen((string) $value);
}
return $length >= $rule;
}