This commit is contained in:
xl
2023-07-07 17:24:03 +08:00
parent 448b1a68fc
commit d18994fde2
11 changed files with 310 additions and 342 deletions
+13 -18
View File
@@ -12,28 +12,23 @@ namespace validator;
class EnumValidator extends BaseValidator
{
public array $value = [];
public array $value = [];
/**
* @return bool
* @throws \ReflectionException
*/
public function trigger(): bool
{
return $this->_validator($this->field, function ($field, $params, $values) {
$value = $params[$field] ?? null;
if (is_null($value)) {
return true;
}
if ($value === '') {
return $this->addError($field, 'The param :attribute value con\'t empty.');
}
if (!in_array($value, $values)) {
$message = 'The param :attribute value(' . $value . ') only in ' . implode(',', $values);
return $this->addError($field, $message);
}
return true;
}, $this->params, $this->value);
}
public function trigger(): bool
{
return $this->_validator($this->field, function ($field, $params, $values) {
$value = $params[$field] ?? null;
if (in_array($value, $values)) {
return true;
}
$message = 'The param :attribute value(' . $value . ') only in ' . implode(',', $values);
return $this->addError($field, $message);
}, $this->params, $this->value);
}
}