Files
kiri-validator/RoundValidator.php
T

37 lines
613 B
PHP
Raw Normal View History

2022-01-09 14:01:11 +08:00
<?php
namespace validator;
use Exception;
/**
* Class RoundValidator
* @package validator
*/
class RoundValidator extends BaseValidator
{
public ?int $value = null;
/**
* @return bool
* @throws Exception
*/
public function trigger(): bool
{
2022-02-18 17:16:45 +08:00
return $this->_validator($this->field, function ($field, $model, $param) {
$value = $model->getAttribute($field);
if ($value == null || round($value, $param) != $value) {
2022-02-25 17:12:15 +08:00
return $this->addError($field,'The param :attribute length error');
2022-02-18 17:16:45 +08:00
}
return true;
}, $this->model, $this->value);
2022-01-09 14:01:11 +08:00
}
}