mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-06 23:02:48 +08:00
Validate类优化
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace think;
|
namespace think;
|
||||||
|
|
||||||
|
use think\File;
|
||||||
use think\Request;
|
use think\Request;
|
||||||
use think\Session;
|
use think\Session;
|
||||||
|
|
||||||
@@ -562,10 +563,10 @@ class Validate
|
|||||||
$result = is_array($value);
|
$result = is_array($value);
|
||||||
break;
|
break;
|
||||||
case 'file':
|
case 'file':
|
||||||
$result = $value instanceof \think\File;
|
$result = $value instanceof File;
|
||||||
break;
|
break;
|
||||||
case 'image':
|
case 'image':
|
||||||
$result = $value instanceof \think\File && in_array($this->getImageType($value->getRealPath()), [1, 2, 3, 6]);
|
$result = $value instanceof File && in_array($this->getImageType($value->getRealPath()), [1, 2, 3, 6]);
|
||||||
break;
|
break;
|
||||||
case 'token':
|
case 'token':
|
||||||
$result = $this->token($value, '__token__', $data);
|
$result = $this->token($value, '__token__', $data);
|
||||||
@@ -629,7 +630,7 @@ class Validate
|
|||||||
*/
|
*/
|
||||||
protected function fileExt($file, $rule)
|
protected function fileExt($file, $rule)
|
||||||
{
|
{
|
||||||
if (!($file instanceof \think\File)) {
|
if (!($file instanceof File)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (is_string($rule)) {
|
if (is_string($rule)) {
|
||||||
@@ -656,7 +657,7 @@ class Validate
|
|||||||
*/
|
*/
|
||||||
protected function fileMime($file, $rule)
|
protected function fileMime($file, $rule)
|
||||||
{
|
{
|
||||||
if (!($file instanceof \think\File)) {
|
if (!($file instanceof File)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (is_string($rule)) {
|
if (is_string($rule)) {
|
||||||
@@ -683,7 +684,7 @@ class Validate
|
|||||||
*/
|
*/
|
||||||
protected function fileSize($file, $rule)
|
protected function fileSize($file, $rule)
|
||||||
{
|
{
|
||||||
if (!($file instanceof \think\File)) {
|
if (!($file instanceof File)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (is_array($file)) {
|
if (is_array($file)) {
|
||||||
@@ -707,7 +708,7 @@ class Validate
|
|||||||
*/
|
*/
|
||||||
protected function image($file, $rule)
|
protected function image($file, $rule)
|
||||||
{
|
{
|
||||||
if (!($file instanceof \think\File)) {
|
if (!($file instanceof File)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$rule = explode(',', $rule);
|
$rule = explode(',', $rule);
|
||||||
@@ -946,7 +947,7 @@ class Validate
|
|||||||
{
|
{
|
||||||
if (is_array($value)) {
|
if (is_array($value)) {
|
||||||
$length = count($value);
|
$length = count($value);
|
||||||
} elseif ($value instanceof \think\File) {
|
} elseif ($value instanceof File) {
|
||||||
$length = $value->getSize();
|
$length = $value->getSize();
|
||||||
} else {
|
} else {
|
||||||
$length = mb_strlen((string) $value);
|
$length = mb_strlen((string) $value);
|
||||||
@@ -973,7 +974,7 @@ class Validate
|
|||||||
{
|
{
|
||||||
if (is_array($value)) {
|
if (is_array($value)) {
|
||||||
$length = count($value);
|
$length = count($value);
|
||||||
} elseif ($value instanceof \think\File) {
|
} elseif ($value instanceof File) {
|
||||||
$length = $value->getSize();
|
$length = $value->getSize();
|
||||||
} else {
|
} else {
|
||||||
$length = mb_strlen((string) $value);
|
$length = mb_strlen((string) $value);
|
||||||
@@ -992,7 +993,7 @@ class Validate
|
|||||||
{
|
{
|
||||||
if (is_array($value)) {
|
if (is_array($value)) {
|
||||||
$length = count($value);
|
$length = count($value);
|
||||||
} elseif ($value instanceof \think\File) {
|
} elseif ($value instanceof File) {
|
||||||
$length = $value->getSize();
|
$length = $value->getSize();
|
||||||
} else {
|
} else {
|
||||||
$length = mb_strlen((string) $value);
|
$length = mb_strlen((string) $value);
|
||||||
|
|||||||
Reference in New Issue
Block a user