This commit is contained in:
2023-12-18 15:01:09 +08:00
parent d860269a7c
commit 645d73453c
15 changed files with 251 additions and 613 deletions
+4 -12
View File
@@ -12,22 +12,14 @@ namespace validator;
class EnumValidator extends BaseValidator
{
public array $value = [];
/**
* @param string $field
* @param mixed $value
* @return bool
*/
public function trigger(): bool
public function trigger(string $field, mixed $value): 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);
return in_array($value, $this->value);
}
}