RockLobsterInc\Swv\Rules
MaxLengthRule::validate
Validates the form data according to the logic defined by this rule.
Метод класса: MaxLengthRule{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
$MaxLengthRule = new MaxLengthRule(); $MaxLengthRule->validate( $form_data, $context );
- $form_data(FormDataTree) (обязательный)
- Form data.
- $context(массив)
- Optional context.
По умолчанию:[]
Код MaxLengthRule::validate() MaxLengthRule::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) or !is_numeric($this->threshold)) {
return true;
}
$total = 0;
foreach ($values as $value) {
$length = count_code_units($value);
if (false === $length) {
// mbstring is not loaded.
return true;
}
$total += $length;
}
if ((int) $this->threshold < $total) {
throw new Invalidity($this, ["cause" => $total]);
}
return true;
}