Files
kiri-validator/RoundValidator.php
T
2023-12-12 15:35:34 +08:00

37 lines
687 B
PHP

<?php
namespace validator;
use Exception;
/**
* Class RoundValidator
* @package validator
*/
class RoundValidator extends BaseValidator
{
public ?int $value = null;
/**
* @return bool
* @throws
*/
public function trigger(): bool
{
return $this->_validator($this->field, function ($field, $model, $param) {
$value = $model->getAttribute($field);
if ($value == null || round($value, $param) != $value) {
return $this->addError($field, 'The param :attribute length error');
}
return true;
}, $this->model, $this->value);
}
}