@@ -34,6 +34,9 @@ final class RsvFormDefinitionValidator {
|
||||
$errors[] = 'Form must contain a submit button.';
|
||||
}
|
||||
|
||||
// Validate membership bindings if present.
|
||||
$errors = array_merge($errors, $this->validate_membership_bindings($definition));
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
@@ -109,4 +112,41 @@ final class RsvFormDefinitionValidator {
|
||||
global $rsv_template_registry;
|
||||
return new RsvTemplateEngine(registry: $rsv_template_registry);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string,mixed> $definition
|
||||
* @return list<string>
|
||||
*/
|
||||
private function validate_membership_bindings(array $definition): array {
|
||||
$errors = [];
|
||||
$membership = $definition['membership'] ?? [];
|
||||
|
||||
if (!is_array($membership)) {
|
||||
return $errors;
|
||||
}
|
||||
|
||||
$bindings = $membership['bindings'] ?? [];
|
||||
if (!is_array($bindings)) {
|
||||
return $errors;
|
||||
}
|
||||
|
||||
foreach ($bindings as $idx => $binding) {
|
||||
if (!is_array($binding)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$program_id = intval($binding['program_id'] ?? 0);
|
||||
$discount = floatval($binding['discount'] ?? 0.0);
|
||||
|
||||
if ($program_id <= 0) {
|
||||
$errors[] = "Membership binding {$idx}: program_id must be a positive integer.";
|
||||
}
|
||||
|
||||
if ($discount < 0.0 || $discount > 100.0) {
|
||||
$errors[] = "Membership binding {$idx}: discount must be between 0 and 100.";
|
||||
}
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user