RockLobsterInc\Swv\Rules
StepNumberRule::validate
Validates the form data according to the logic defined by this rule.
Метод класса: StepNumberRule{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
$StepNumberRule = new StepNumberRule(); $StepNumberRule->validate( $form_data, $context );
- $form_data(FormDataTree) (обязательный)
- Form data.
- $context(массив)
- Optional context.
По умолчанию:[]
Код StepNumberRule::validate() StepNumberRule::validate CF7 6.2.4.1
public function validate(FormDataTree $form_data, array $context = [])
{
$values = $form_data->getAll($this->field);
$values = array_flatten($values);
if (empty($values)) {
return true;
}
$base = floatval($this->base);
$interval = floatval($this->interval);
if (!(0 < $interval)) {
return true;
}
foreach ($values as $value) {
if (!NumberRule::isNumber($value)) {
continue;
}
$remainder = fmod(floatval($value) - $base, $interval);
if (
0.0 === round(abs($remainder), 6) or
0.0 === round(abs($remainder - $interval), 6)
) {
continue;
}
throw new Invalidity($this, ["cause" => $value]);
}
return true;
}