Files
kiri-validator/EnumValidator.php
T

31 lines
568 B
PHP
Raw Normal View History

2022-01-09 14:01:11 +08:00
<?php
declare(strict_types=1);
namespace validator;
/**
* Class EnumValidator
* @package validator
*/
class EnumValidator extends BaseValidator
{
public array $value = [];
/**
* @return bool
*/
public function trigger(): bool
{
2022-02-18 17:16:45 +08:00
return $this->_validator($this->field, function ($field, $params, $values) {
2022-03-01 16:33:02 +08:00
if (!in_array($params[$field] ?? null, $values)) {
2022-02-25 17:12:15 +08:00
return $this->addError($field,'The param :attribute value only in ' . implode(',', $values));
2022-02-18 17:16:45 +08:00
}
return true;
}, $this->params, $this->value);
2022-01-09 14:01:11 +08:00
}
}