This commit is contained in:
2023-10-24 17:22:29 +08:00
parent f194684d4b
commit 26030fd148
10 changed files with 43 additions and 40 deletions
-3
View File
@@ -10,8 +10,6 @@ declare(strict_types=1);
namespace validator; namespace validator;
use ReflectionException;
/** /**
* Class ArrayValidator * Class ArrayValidator
* @package validator * @package validator
@@ -23,7 +21,6 @@ class ArrayValidator extends BaseValidator
* @return bool * @return bool
* *
* 检查 * 检查
* @throws ReflectionException
*/ */
public function trigger(): bool public function trigger(): bool
{ {
+4
View File
@@ -7,6 +7,10 @@ namespace validator;
use Database\Model; use Database\Model;
use Exception; use Exception;
/**
* Class \validator\BaseValidator
*/
abstract class BaseValidator abstract class BaseValidator
{ {
+28 -24
View File
@@ -39,12 +39,13 @@ class DateTimeValidator extends BaseValidator
} }
/** /**
* @param $value * @param $field
* @return bool * @param $value
* * @return bool
* 效验分秒 格式如 01:02 or 01-02 *
*/ * 效验分秒 格式如 01:02 or 01-02
*/
public function validatorTime($field, $value): bool public function validatorTime($field, $value): bool
{ {
if (!is_string($value)) { if (!is_string($value)) {
@@ -59,12 +60,13 @@ class DateTimeValidator extends BaseValidator
} }
/** /**
* @param $value * @param $field
* @return bool * @param $value
* * @return bool
* 效验分秒 格式如 2017-12-22 01:02 *
*/ * 效验分秒 格式如 2017-12-22 01:02
*/
public function validateDatetime($field, $value): bool public function validateDatetime($field, $value): bool
{ {
if (!is_string($value)) { if (!is_string($value)) {
@@ -79,12 +81,13 @@ class DateTimeValidator extends BaseValidator
} }
} }
/** /**
* @param $value * @param $field
* @return bool * @param $value
* * @return bool
* 效验分秒 格式如 2017-12-22 *
*/ * 效验分秒 格式如 2017-12-22
*/
public function validatorDate($field, $value): bool public function validatorDate($field, $value): bool
{ {
if (!is_string($value)) { if (!is_string($value)) {
@@ -98,12 +101,13 @@ class DateTimeValidator extends BaseValidator
} }
} }
/** /**
* @param $value * @param $field
* @return bool * @param $value
* * @return bool
* 效验时间戳 格式如 1521452254 *
*/ * 效验时间戳 格式如 1521452254
*/
public function validatorTimestamp($field, $value): bool public function validatorTimestamp($field, $value): bool
{ {
if (!is_numeric($value)) { if (!is_numeric($value)) {
+3 -2
View File
@@ -9,14 +9,15 @@ declare(strict_types=1);
namespace validator; namespace validator;
/**
*
*/
class EmailValidator extends BaseValidator class EmailValidator extends BaseValidator
{ {
/** /**
* @return bool * @return bool
* 检查是否存在 * 检查是否存在
* @throws \ReflectionException
*/ */
public function trigger(): bool public function trigger(): bool
{ {
+3 -3
View File
@@ -12,8 +12,9 @@ declare(strict_types=1);
namespace validator; namespace validator;
use ReflectionException; /**
*
*/
class EmptyValidator extends BaseValidator class EmptyValidator extends BaseValidator
{ {
@@ -29,7 +30,6 @@ class EmptyValidator extends BaseValidator
* @return bool * @return bool
* *
* 检查参数是否为NULL * 检查参数是否为NULL
* @throws ReflectionException
*/ */
public function trigger(): bool public function trigger(): bool
{ {
-1
View File
@@ -16,7 +16,6 @@ class EnumValidator extends BaseValidator
/** /**
* @return bool * @return bool
* @throws \ReflectionException
*/ */
public function trigger(): bool public function trigger(): bool
{ {
+3 -1
View File
@@ -10,6 +10,9 @@ declare(strict_types=1);
namespace validator; namespace validator;
/**
*
*/
class IntegerValidator extends BaseValidator class IntegerValidator extends BaseValidator
{ {
@@ -21,7 +24,6 @@ class IntegerValidator extends BaseValidator
/** /**
* @return bool * @return bool
* @throws \ReflectionException
*/ */
public function trigger(): bool public function trigger(): bool
{ {
-3
View File
@@ -10,8 +10,6 @@ declare(strict_types=1);
namespace validator; namespace validator;
use ReflectionException;
class LengthValidator extends BaseValidator class LengthValidator extends BaseValidator
{ {
@@ -24,7 +22,6 @@ class LengthValidator extends BaseValidator
/** /**
* @return bool * @return bool
* @throws ReflectionException
*/ */
public function trigger(): bool public function trigger(): bool
{ {
-1
View File
@@ -16,7 +16,6 @@ class RequiredValidator extends BaseValidator
/** /**
* @return bool * @return bool
* 检查是否存在 * 检查是否存在
* @throws \ReflectionException
*/ */
public function trigger(): bool public function trigger(): bool
{ {
+2 -2
View File
@@ -112,10 +112,10 @@ class Validator extends BaseValidator
/** /**
* @param BaseValidator|array|Closure $val * @param BaseValidator|array|Closure $val
* @return mixed * @return array
* @throws Exception * @throws Exception
*/ */
private function check(BaseValidator|array|Closure $val): mixed private function check(BaseValidator|array|Closure $val): array
{ {
if (is_callable($val, true)) { if (is_callable($val, true)) {
return [call_user_func($val, $this), $val]; return [call_user_func($val, $this), $val];