qqq
This commit is contained in:
+18
-18
@@ -15,13 +15,13 @@ namespace validator;
|
||||
class EmptyValidator extends BaseValidator
|
||||
{
|
||||
|
||||
/** @var string [不能为空] */
|
||||
const CAN_NOT_EMPTY = 'not empty';
|
||||
/** @var string [不能为空] */
|
||||
const CAN_NOT_EMPTY = 'not empty';
|
||||
|
||||
/** @var string [可为空, 不能为null] */
|
||||
const CAN_NOT_NULL = 'not null';
|
||||
/** @var string [可为空, 不能为null] */
|
||||
const CAN_NOT_NULL = 'not null';
|
||||
|
||||
public string $method;
|
||||
public string $method;
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
@@ -29,17 +29,17 @@ class EmptyValidator extends BaseValidator
|
||||
* 检查参数是否为NULL
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
public function trigger(): bool
|
||||
{
|
||||
return $this->_validator($this->field, function ($field, $params, $method) {
|
||||
$value = $params[$field] ?? null;
|
||||
if (empty($value)) {
|
||||
return $this->addError($field,':attribute not exists');
|
||||
}
|
||||
return match ($method) {
|
||||
self::CAN_NOT_EMPTY => isset($value[1]) || $this->addError($field,'The :attribute can not empty.'),
|
||||
default => $value !== null || $this->addError($field,'The :attribute can not empty.')
|
||||
};
|
||||
}, $this->params, strtolower($this->method));
|
||||
}
|
||||
public function trigger(): bool
|
||||
{
|
||||
return $this->_validator($this->field, function ($field, $params, $method) {
|
||||
$value = $params[$field] ?? null;
|
||||
if ($value === null) {
|
||||
return $this->addError($field, 'The :attribute can not null.');
|
||||
}
|
||||
if (empty($value)) {
|
||||
return $this->addError($field, 'The :attribute can not empty.');
|
||||
}
|
||||
return true;
|
||||
}, $this->params, strtolower($this->method));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user