id = $this->validateId($id); $this->formId = $this->validateId($formId); $this->type = $this->validateString($type, 255, 'type'); $this->enabled = $this->validateBool($enabled); $this->showForm = $this->validateBool($showForm); $this->message = $this->validateString($message, 1000, 'message'); $this->url = $this->validateString($url, 255, 'url'); $this->page = $this->validateString($page, 255, 'page'); } /** * Validates the ID. * * @param int $id * * @return int * @throws InvalidArgumentException */ private function validateId(int $id): int { if ($id < 0) { throw new InvalidArgumentException("Id must be a positive integer."); } return $id; } /** * Validates a string value. * * @param string $value * @param int $maxLength * @param string $fieldName * * @return string * * @throws ValidationException */ private function validateString(string $value, int $maxLength, string $fieldName): string { if (strlen($value) > $maxLength) { throw new ValidationException( sprintf( /* translators: 1: String value, 2: String max length. */ esc_html__('%1$s must be at most %2$d characters.', 'ivyforms'), esc_html($fieldName), $maxLength ) ); } return $value; } /** * Validates a boolean field. * * @param bool $value * * @return bool */ private function validateBool(bool $value): bool { return $value; } /** * Get the confirmation ID. * * @return int */ public function getId(): int { return $this->id; } /** * Get the form ID. * * @return int */ public function getFormId(): int { return $this->formId; } /** * Get the confirmation type. * * @return string */ public function getType(): string { return $this->type; } /** * Get the confirmation status. * * @return bool */ public function isEnabled(): bool { return $this->enabled; } /** * Get the show form flag. * * @return bool */ public function isShowForm(): bool { return $this->showForm; } /** * Get the confirmation message. * * @return string */ public function getMessage(): string { return $this->message; } /** * Get the confirmation URL. * * @return string */ public function getUrl(): string { return $this->url; } /** * Get the confirmation page. * * @return string */ public function getPage(): string { return $this->page; } /** * Convert the confirmation to an array. * * @return array */ public function toArray(): array { return [ 'id' => $this->getId(), 'formId' => $this->getFormId(), 'type' => $this->getType(), 'enabled' => $this->isEnabled(), 'showForm' => $this->isShowForm(), 'message' => $this->getMessage(), 'url' => $this->getUrl(), 'page' => $this->getPage(), ]; } }