qqq
This commit is contained in:
+13
-18
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user