eee
This commit is contained in:
+3
-3
@@ -71,7 +71,7 @@ abstract class BaseValidator
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool
|
||||||
* @throws Exception
|
* @throws
|
||||||
*/
|
*/
|
||||||
public function trigger(): bool
|
public function trigger(): bool
|
||||||
{
|
{
|
||||||
@@ -109,7 +109,7 @@ abstract class BaseValidator
|
|||||||
$message = str_replace(':attribute', $field, $message);
|
$message = str_replace(':attribute', $field, $message);
|
||||||
}
|
}
|
||||||
|
|
||||||
\trigger_print_error($message,"mysql");
|
\trigger_print_error($message, "mysql");
|
||||||
$this->message = $message;
|
$this->message = $message;
|
||||||
|
|
||||||
return $this->isFail;
|
return $this->isFail;
|
||||||
@@ -147,7 +147,7 @@ abstract class BaseValidator
|
|||||||
/**
|
/**
|
||||||
* @param $name
|
* @param $name
|
||||||
* @param $value
|
* @param $value
|
||||||
* @throws Exception
|
* @throws
|
||||||
*/
|
*/
|
||||||
public function __set($name, $value)
|
public function __set($name, $value)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,10 +13,10 @@ namespace validator;
|
|||||||
class DateTimeValidator extends BaseValidator
|
class DateTimeValidator extends BaseValidator
|
||||||
{
|
{
|
||||||
|
|
||||||
const DATE = 'date';
|
const string DATE = 'date';
|
||||||
const DATE_TIME = 'datetime';
|
const string DATE_TIME = 'datetime';
|
||||||
const TIME = 'time';
|
const string TIME = 'time';
|
||||||
const STR_TO_TIME = 'timestamp';
|
const string STR_TO_TIME = 'timestamp';
|
||||||
|
|
||||||
public string $method;
|
public string $method;
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -19,10 +19,10 @@ class EmptyValidator extends BaseValidator
|
|||||||
{
|
{
|
||||||
|
|
||||||
/** @var string [不能为空] */
|
/** @var string [不能为空] */
|
||||||
const CAN_NOT_EMPTY = 'not empty';
|
const string CAN_NOT_EMPTY = 'not empty';
|
||||||
|
|
||||||
/** @var string [可为空, 不能为null] */
|
/** @var string [可为空, 不能为null] */
|
||||||
const CAN_NOT_NULL = 'not null';
|
const string CAN_NOT_NULL = 'not null';
|
||||||
|
|
||||||
public string $method;
|
public string $method;
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -13,8 +13,8 @@ namespace validator;
|
|||||||
class LengthValidator extends BaseValidator
|
class LengthValidator extends BaseValidator
|
||||||
{
|
{
|
||||||
|
|
||||||
const MAX_LENGTH = 'max';
|
const string MAX_LENGTH = 'max';
|
||||||
const MIN_LENGTH = 'min';
|
const string MIN_LENGTH = 'min';
|
||||||
|
|
||||||
public string $method;
|
public string $method;
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -19,14 +19,14 @@ class RoundValidator extends BaseValidator
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool
|
||||||
* @throws Exception
|
* @throws
|
||||||
*/
|
*/
|
||||||
public function trigger(): bool
|
public function trigger(): bool
|
||||||
{
|
{
|
||||||
return $this->_validator($this->field, function ($field, $model, $param) {
|
return $this->_validator($this->field, function ($field, $model, $param) {
|
||||||
$value = $model->getAttribute($field);
|
$value = $model->getAttribute($field);
|
||||||
if ($value == null || round($value, $param) != $value) {
|
if ($value == null || round($value, $param) != $value) {
|
||||||
return $this->addError($field,'The param :attribute length error');
|
return $this->addError($field, 'The param :attribute length error');
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}, $this->model, $this->value);
|
}, $this->model, $this->value);
|
||||||
|
|||||||
@@ -14,11 +14,11 @@ class TypesOfValidator extends BaseValidator
|
|||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
const JSON = 'json';
|
const string JSON = 'json';
|
||||||
const FLOAT = 'float';
|
const string FLOAT = 'float';
|
||||||
const ARRAY = 'array';
|
const string ARRAY = 'array';
|
||||||
const STRING = 'string';
|
const string STRING = 'string';
|
||||||
const INTEGER = 'integer';
|
const string INTEGER = 'integer';
|
||||||
|
|
||||||
private ?int $min = null;
|
private ?int $min = null;
|
||||||
private ?int $max = null;
|
private ?int $max = null;
|
||||||
|
|||||||
+4
-5
@@ -7,7 +7,6 @@ namespace validator;
|
|||||||
|
|
||||||
use Closure;
|
use Closure;
|
||||||
use Database\ModelInterface;
|
use Database\ModelInterface;
|
||||||
use Exception;
|
|
||||||
use Kiri;
|
use Kiri;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -40,7 +39,7 @@ class Validator extends BaseValidator
|
|||||||
* @param $field
|
* @param $field
|
||||||
* @param $rules
|
* @param $rules
|
||||||
* @return $this
|
* @return $this
|
||||||
* @throws Exception
|
* @throws
|
||||||
*/
|
*/
|
||||||
public function make($field, $rules): static
|
public function make($field, $rules): static
|
||||||
{
|
{
|
||||||
@@ -61,7 +60,7 @@ class Validator extends BaseValidator
|
|||||||
* @param $rule
|
* @param $rule
|
||||||
* @param $model
|
* @param $model
|
||||||
* @param $param
|
* @param $param
|
||||||
* @throws Exception
|
* @throws
|
||||||
* ['maxLength'=>150, 'required', 'minLength' => 100]
|
* ['maxLength'=>150, 'required', 'minLength' => 100]
|
||||||
*/
|
*/
|
||||||
public function createRule($field, $rule, $model, $param): void
|
public function createRule($field, $rule, $model, $param): void
|
||||||
@@ -88,7 +87,7 @@ class Validator extends BaseValidator
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool
|
||||||
* @throws Exception
|
* @throws
|
||||||
*/
|
*/
|
||||||
public function validation(): bool
|
public function validation(): bool
|
||||||
{
|
{
|
||||||
@@ -113,7 +112,7 @@ class Validator extends BaseValidator
|
|||||||
/**
|
/**
|
||||||
* @param BaseValidator|array|Closure $val
|
* @param BaseValidator|array|Closure $val
|
||||||
* @return array
|
* @return array
|
||||||
* @throws Exception
|
* @throws
|
||||||
*/
|
*/
|
||||||
private function check(BaseValidator|array|Closure $val): array
|
private function check(BaseValidator|array|Closure $val): array
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user