run_public_id = $run_public_id; $this->purpose = $purpose; $this->url = $url; $this->expires_at = $expires_at; } public function is_available(): bool { $expires_at = strtotime( $this->expires_at ); return false !== $expires_at && $expires_at > time() + 30; } /** @return array{run_public_id: string, purpose: string, url: string, expires_at: string} */ public function to_payload(): array { return array( 'run_public_id' => $this->run_public_id, 'purpose' => $this->purpose, 'url' => $this->url, 'expires_at' => $this->expires_at, ); } /** @param array $payload API or local option boundary payload. */ public static function from_payload( array $payload, string $run_public_id, string $purpose ): ?self { $url = $payload['url'] ?? null; $expires_at = $payload['expires_at'] ?? null; if ( ! is_string( $url ) || ! is_string( $expires_at ) || ! self::valid_url( $url ) ) { return null; } return new self( $run_public_id, $purpose, $url, $expires_at ); } private static function valid_url( string $url ): bool { $scheme = wp_parse_url( $url, PHP_URL_SCHEME ); $host = wp_parse_url( $url, PHP_URL_HOST ); return 'https' === $scheme && '2-ua.com' === strtolower( is_string( $host ) ? $host : '' ); } }