Files
kiri-validator/RequiredValidator.php
T

32 lines
553 B
PHP
Raw Normal View History

2022-01-09 14:01:11 +08:00
<?php
/**
* Created by PhpStorm.
* User: whwyy
* Date: 2018/4/3 0003
* Time: 15:47
*/
declare(strict_types=1);
namespace validator;
class RequiredValidator extends BaseValidator
{
2023-07-07 17:24:03 +08:00
/**
* @return bool
* 检查是否存在
*/
2022-01-09 14:01:11 +08:00
public function trigger(): bool
{
2022-02-18 17:16:45 +08:00
return $this->_validator($this->field, function ($field, $params) {
if (!isset($params[$field])) {
2022-02-25 17:12:15 +08:00
return $this->addError($field,'The param :attribute not exists');
2022-02-18 17:16:45 +08:00
} else {
return true;
}
2022-03-01 16:18:49 +08:00
}, $this->params);
2022-01-09 14:01:11 +08:00
}
}