author = $this->validateString($author, 1000, 'author'); $this->starred = $starred; $this->published = $published; $this->dateCreated = $dateCreated ?? $now; $this->dateEdited = $dateEdited ?? $now; } /** * 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; } /** * @return string */ public function getAuthor(): string { return $this->author; } /** * @return bool */ public function isStarred(): bool { return $this->starred; } /** * @return bool */ public function isPublished(): bool { return $this->published; } /** * @return string */ public function getDateCreated(): string { return $this->dateCreated; } /** * @return string */ public function getDateEdited(): string { return $this->dateEdited; } /** * Convert to array * * @return array */ public function toArray(): array { return [ 'author' => $this->author, 'starred' => $this->starred, 'published' => $this->published, 'dateCreated' => $this->dateCreated, 'dateEdited' => $this->dateEdited, ]; } }