self::MAX_VERSION_LENGTH ) { // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- Not HTML output here; escaped where printed. throw new ReleaseValidationException( __( 'A release version cannot be longer than 32 characters.', 'releasecart' ) ); } if ( '' === $storageKey ) { // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- Not HTML output here; escaped where printed. throw new ReleaseValidationException( __( 'A release must have a storage key for its package.', 'releasecart' ) ); } if ( strlen( $storageKey ) > self::MAX_STORAGE_KEY_LENGTH ) { // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- Not HTML output here; escaped where printed. throw new ReleaseValidationException( __( 'A release storage key cannot be longer than 500 characters.', 'releasecart' ) ); } $this->id = $id; $this->productId = $productId; $this->version = $version; $this->storageProvider = $storageProvider; $this->storageKey = $storageKey; $this->filesize = $filesize; $this->checksumSha256 = $checksumSha256; $this->requiresWp = $requiresWp; $this->testedUpTo = $testedUpTo; $this->requiresPhp = $requiresPhp; $this->changelog = $changelog; $this->status = $status; $this->releasedAt = $releasedAt; $this->createdAt = $createdAt; $this->updatedAt = $updatedAt; } /** * Whether the release is currently published. * * @since 1.0.0 * * @return bool True when the release is published. */ public function isPublished(): bool { return ReleaseStatus::Published === $this->status; } /** * Return a copy with a new status. * * @since 1.0.0 * * @param ReleaseStatus $status The status the copy should carry. * @return self The new release. */ public function withStatus( ReleaseStatus $status ): self { return new self( $this->id, $this->productId, $this->version, $this->storageProvider, $this->storageKey, $this->filesize, $this->checksumSha256, $this->requiresWp, $this->testedUpTo, $this->requiresPhp, $this->changelog, $status, $this->releasedAt, $this->createdAt, $this->updatedAt ); } /** * The primary key, or null when unsaved. * * @since 1.0.0 * * @return int|null */ public function id(): ?int { return $this->id; } /** * The owning product id. * * @since 1.0.0 * * @return int */ public function productId(): int { return $this->productId; } /** * The version string. * * @since 1.0.0 * * @return string */ public function version(): string { return $this->version; } /** * The storage adapter id the package lives under. * * @since 1.0.0 * * @return string */ public function storageProvider(): string { return $this->storageProvider; } /** * The provider-scoped package key. * * @since 1.0.0 * * @return string */ public function storageKey(): string { return $this->storageKey; } /** * The package size in bytes, or null. * * @since 1.0.0 * * @return int|null */ public function filesize(): ?int { return $this->filesize; } /** * The package SHA-256 checksum, or null. * * @since 1.0.0 * * @return string|null */ public function checksumSha256(): ?string { return $this->checksumSha256; } /** * The minimum required WordPress version, or null. * * @since 1.0.0 * * @return string|null */ public function requiresWp(): ?string { return $this->requiresWp; } /** * The highest tested WordPress version, or null. * * @since 1.0.0 * * @return string|null */ public function testedUpTo(): ?string { return $this->testedUpTo; } /** * The minimum required PHP version, or null. * * @since 1.0.0 * * @return string|null */ public function requiresPhp(): ?string { return $this->requiresPhp; } /** * The Markdown changelog source, or null. * * @since 1.0.0 * * @return string|null */ public function changelog(): ?string { return $this->changelog; } /** * The lifecycle status. * * @since 1.0.0 * * @return ReleaseStatus */ public function status(): ReleaseStatus { return $this->status; } /** * The publish instant, or null while still a draft. * * @since 1.0.0 * * @return DateTimeImmutable|null */ public function releasedAt(): ?DateTimeImmutable { return $this->releasedAt; } /** * The creation instant, or null before the first persist. * * @since 1.0.0 * * @return DateTimeImmutable|null */ public function createdAt(): ?DateTimeImmutable { return $this->createdAt; } /** * The last-update instant, or null before the first persist. * * @since 1.0.0 * * @return DateTimeImmutable|null */ public function updatedAt(): ?DateTimeImmutable { return $this->updatedAt; } }