@@ -18,416 +18,416 @@ |
||
| 18 | 18 | * @since 30.0.0 |
| 19 | 19 | */ |
| 20 | 20 | final class Task implements \JsonSerializable { |
| 21 | - protected ?int $id = null; |
|
| 22 | - |
|
| 23 | - protected ?DateTime $completionExpectedAt = null; |
|
| 24 | - |
|
| 25 | - protected ?array $output = null; |
|
| 26 | - |
|
| 27 | - protected ?string $errorMessage = null; |
|
| 28 | - |
|
| 29 | - protected ?float $progress = null; |
|
| 30 | - |
|
| 31 | - protected int $lastUpdated; |
|
| 32 | - |
|
| 33 | - protected ?string $webhookUri = null; |
|
| 34 | - |
|
| 35 | - protected ?string $webhookMethod = null; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * @psalm-var self::STATUS_* |
|
| 39 | - */ |
|
| 40 | - protected int $status = self::STATUS_UNKNOWN; |
|
| 41 | - |
|
| 42 | - protected ?int $scheduledAt = null; |
|
| 43 | - |
|
| 44 | - protected ?int $startedAt = null; |
|
| 45 | - |
|
| 46 | - protected ?int $endedAt = null; |
|
| 47 | - |
|
| 48 | - protected bool $allowCleanup = true; |
|
| 49 | - |
|
| 50 | - protected ?string $userFacingErrorMessage = null; |
|
| 51 | - |
|
| 52 | - protected bool $includeWatermark = true; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * @since 30.0.0 |
|
| 56 | - */ |
|
| 57 | - public const STATUS_CANCELLED = 5; |
|
| 58 | - /** |
|
| 59 | - * @since 30.0.0 |
|
| 60 | - */ |
|
| 61 | - public const STATUS_FAILED = 4; |
|
| 62 | - /** |
|
| 63 | - * @since 30.0.0 |
|
| 64 | - */ |
|
| 65 | - public const STATUS_SUCCESSFUL = 3; |
|
| 66 | - /** |
|
| 67 | - * @since 30.0.0 |
|
| 68 | - */ |
|
| 69 | - public const STATUS_RUNNING = 2; |
|
| 70 | - /** |
|
| 71 | - * @since 30.0.0 |
|
| 72 | - */ |
|
| 73 | - public const STATUS_SCHEDULED = 1; |
|
| 74 | - /** |
|
| 75 | - * @since 30.0.0 |
|
| 76 | - */ |
|
| 77 | - public const STATUS_UNKNOWN = 0; |
|
| 78 | - |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * @param string $taskTypeId |
|
| 82 | - * @param array<string,list<numeric|string>|numeric|string> $input |
|
| 83 | - * @param string $appId |
|
| 84 | - * @param string|null $userId |
|
| 85 | - * @param null|string $customId An arbitrary customId for this task. max length: 255 chars |
|
| 86 | - * @since 30.0.0 |
|
| 87 | - */ |
|
| 88 | - final public function __construct( |
|
| 89 | - protected readonly string $taskTypeId, |
|
| 90 | - protected array $input, |
|
| 91 | - protected readonly string $appId, |
|
| 92 | - protected readonly ?string $userId, |
|
| 93 | - protected readonly ?string $customId = '', |
|
| 94 | - ) { |
|
| 95 | - $this->lastUpdated = time(); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * @since 30.0.0 |
|
| 100 | - */ |
|
| 101 | - final public function getTaskTypeId(): string { |
|
| 102 | - return $this->taskTypeId; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * @psalm-return self::STATUS_* |
|
| 107 | - * @since 30.0.0 |
|
| 108 | - */ |
|
| 109 | - final public function getStatus(): int { |
|
| 110 | - return $this->status; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * @psalm-param self::STATUS_* $status |
|
| 115 | - * @since 30.0.0 |
|
| 116 | - */ |
|
| 117 | - final public function setStatus(int $status): void { |
|
| 118 | - $this->status = $status; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * @param ?DateTime $at |
|
| 123 | - * @since 30.0.0 |
|
| 124 | - */ |
|
| 125 | - final public function setCompletionExpectedAt(?DateTime $at): void { |
|
| 126 | - $this->completionExpectedAt = $at; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * @return ?DateTime |
|
| 131 | - * @since 30.0.0 |
|
| 132 | - */ |
|
| 133 | - final public function getCompletionExpectedAt(): ?DateTime { |
|
| 134 | - return $this->completionExpectedAt; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * @return int|null |
|
| 139 | - * @since 30.0.0 |
|
| 140 | - */ |
|
| 141 | - final public function getId(): ?int { |
|
| 142 | - return $this->id; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * @param int|null $id |
|
| 147 | - * @since 30.0.0 |
|
| 148 | - */ |
|
| 149 | - final public function setId(?int $id): void { |
|
| 150 | - $this->id = $id; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * @param null|array<array-key, list<numeric|string>|numeric|string> $output |
|
| 155 | - * @since 30.0.0 |
|
| 156 | - */ |
|
| 157 | - final public function setOutput(?array $output): void { |
|
| 158 | - $this->output = $output; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * @return array<array-key, list<numeric|string>|numeric|string>|null |
|
| 163 | - * @since 30.0.0 |
|
| 164 | - */ |
|
| 165 | - final public function getOutput(): ?array { |
|
| 166 | - return $this->output; |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * @return array<array-key, list<numeric|string>|numeric|string> |
|
| 171 | - * @since 30.0.0 |
|
| 172 | - */ |
|
| 173 | - final public function getInput(): array { |
|
| 174 | - return $this->input; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * @return string |
|
| 179 | - * @since 30.0.0 |
|
| 180 | - */ |
|
| 181 | - final public function getAppId(): string { |
|
| 182 | - return $this->appId; |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * @return null|string |
|
| 187 | - * @since 30.0.0 |
|
| 188 | - */ |
|
| 189 | - final public function getCustomId(): ?string { |
|
| 190 | - return $this->customId; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * @return string|null |
|
| 195 | - * @since 30.0.0 |
|
| 196 | - */ |
|
| 197 | - final public function getUserId(): ?string { |
|
| 198 | - return $this->userId; |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - /** |
|
| 202 | - * @return int |
|
| 203 | - * @since 30.0.0 |
|
| 204 | - */ |
|
| 205 | - final public function getLastUpdated(): int { |
|
| 206 | - return $this->lastUpdated; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * @param int $lastUpdated |
|
| 211 | - * @since 30.0.0 |
|
| 212 | - */ |
|
| 213 | - final public function setLastUpdated(int $lastUpdated): void { |
|
| 214 | - $this->lastUpdated = $lastUpdated; |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * @return int|null |
|
| 219 | - * @since 30.0.0 |
|
| 220 | - */ |
|
| 221 | - final public function getScheduledAt(): ?int { |
|
| 222 | - return $this->scheduledAt; |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - /** |
|
| 226 | - * @param int|null $scheduledAt |
|
| 227 | - * @since 30.0.0 |
|
| 228 | - */ |
|
| 229 | - final public function setScheduledAt(?int $scheduledAt): void { |
|
| 230 | - $this->scheduledAt = $scheduledAt; |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * @return int|null |
|
| 235 | - * @since 30.0.0 |
|
| 236 | - */ |
|
| 237 | - final public function getStartedAt(): ?int { |
|
| 238 | - return $this->startedAt; |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - /** |
|
| 242 | - * @param int|null $startedAt |
|
| 243 | - * @since 30.0.0 |
|
| 244 | - */ |
|
| 245 | - final public function setStartedAt(?int $startedAt): void { |
|
| 246 | - $this->startedAt = $startedAt; |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * @return int|null |
|
| 251 | - * @since 30.0.0 |
|
| 252 | - */ |
|
| 253 | - final public function getEndedAt(): ?int { |
|
| 254 | - return $this->endedAt; |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - /** |
|
| 258 | - * @param int|null $endedAt |
|
| 259 | - * @since 30.0.0 |
|
| 260 | - */ |
|
| 261 | - final public function setEndedAt(?int $endedAt): void { |
|
| 262 | - $this->endedAt = $endedAt; |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - /** |
|
| 266 | - * @return bool |
|
| 267 | - * @since 32.0.0 |
|
| 268 | - */ |
|
| 269 | - final public function getAllowCleanup(): bool { |
|
| 270 | - return $this->allowCleanup; |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - /** |
|
| 274 | - * @param bool $allowCleanup |
|
| 275 | - * @since 32.0.0 |
|
| 276 | - */ |
|
| 277 | - final public function setAllowCleanup(bool $allowCleanup): void { |
|
| 278 | - $this->allowCleanup = $allowCleanup; |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - /** |
|
| 282 | - * @return bool |
|
| 283 | - * @since 33.0.0 |
|
| 284 | - */ |
|
| 285 | - final public function getIncludeWatermark(): bool { |
|
| 286 | - return $this->includeWatermark; |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - /** |
|
| 290 | - * @param bool $includeWatermark |
|
| 291 | - * @since 33.0.0 |
|
| 292 | - */ |
|
| 293 | - final public function setIncludeWatermark(bool $includeWatermark): void { |
|
| 294 | - $this->includeWatermark = $includeWatermark; |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - /** |
|
| 298 | - * @psalm-return array{id: int, lastUpdated: int, type: string, status: 'STATUS_CANCELLED'|'STATUS_FAILED'|'STATUS_SUCCESSFUL'|'STATUS_RUNNING'|'STATUS_SCHEDULED'|'STATUS_UNKNOWN', userId: ?string, appId: string, input: array<string, list<numeric|string>|numeric|string>, output: ?array<string, list<numeric|string>|numeric|string>, customId: ?string, completionExpectedAt: ?int, progress: ?float, scheduledAt: ?int, startedAt: ?int, endedAt: ?int, allowCleanup: bool, includeWatermark: bool, userFacingErrorMessage: ?string} |
|
| 299 | - * @since 30.0.0 |
|
| 300 | - */ |
|
| 301 | - final public function jsonSerialize(): array { |
|
| 302 | - return [ |
|
| 303 | - 'id' => (int)$this->getId(), |
|
| 304 | - 'type' => $this->getTaskTypeId(), |
|
| 305 | - 'lastUpdated' => $this->getLastUpdated(), |
|
| 306 | - 'status' => self::statusToString($this->getStatus()), |
|
| 307 | - 'userId' => $this->getUserId(), |
|
| 308 | - 'appId' => $this->getAppId(), |
|
| 309 | - 'input' => $this->getInput(), |
|
| 310 | - 'output' => $this->getOutput(), |
|
| 311 | - 'customId' => $this->getCustomId(), |
|
| 312 | - 'completionExpectedAt' => $this->getCompletionExpectedAt()?->getTimestamp(), |
|
| 313 | - 'progress' => $this->getProgress(), |
|
| 314 | - 'scheduledAt' => $this->getScheduledAt(), |
|
| 315 | - 'startedAt' => $this->getStartedAt(), |
|
| 316 | - 'endedAt' => $this->getEndedAt(), |
|
| 317 | - 'allowCleanup' => $this->getAllowCleanup(), |
|
| 318 | - 'includeWatermark' => $this->getIncludeWatermark(), |
|
| 319 | - 'userFacingErrorMessage' => $this->getUserFacingErrorMessage(), |
|
| 320 | - ]; |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - /** |
|
| 324 | - * @param string|null $error |
|
| 325 | - * @return void |
|
| 326 | - * @since 30.0.0 |
|
| 327 | - */ |
|
| 328 | - final public function setErrorMessage(?string $error) { |
|
| 329 | - $this->errorMessage = $error; |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - /** |
|
| 333 | - * @return string|null |
|
| 334 | - * @since 30.0.0 |
|
| 335 | - */ |
|
| 336 | - final public function getErrorMessage(): ?string { |
|
| 337 | - return $this->errorMessage; |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - /** |
|
| 341 | - * @param array $input |
|
| 342 | - * @return void |
|
| 343 | - * @since 30.0.0 |
|
| 344 | - */ |
|
| 345 | - final public function setInput(array $input): void { |
|
| 346 | - $this->input = $input; |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - /** |
|
| 350 | - * @param float|null $progress |
|
| 351 | - * @return void |
|
| 352 | - * @throws ValidationException |
|
| 353 | - * @since 30.0.0 |
|
| 354 | - */ |
|
| 355 | - final public function setProgress(?float $progress): void { |
|
| 356 | - if ($progress < 0 || $progress > 1.0) { |
|
| 357 | - throw new ValidationException('Progress must be between 0.0 and 1.0 inclusively; ' . $progress . ' given'); |
|
| 358 | - } |
|
| 359 | - $this->progress = $progress; |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - /** |
|
| 363 | - * @return float|null |
|
| 364 | - * @since 30.0.0 |
|
| 365 | - */ |
|
| 366 | - final public function getProgress(): ?float { |
|
| 367 | - return $this->progress; |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - /** |
|
| 371 | - * @return null|string |
|
| 372 | - * @since 30.0.0 |
|
| 373 | - */ |
|
| 374 | - final public function getWebhookUri(): ?string { |
|
| 375 | - return $this->webhookUri; |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - /** |
|
| 379 | - * @param string|null $webhookUri |
|
| 380 | - * @return void |
|
| 381 | - * @since 30.0.0 |
|
| 382 | - */ |
|
| 383 | - final public function setWebhookUri(?string $webhookUri): void { |
|
| 384 | - $this->webhookUri = $webhookUri; |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - /** |
|
| 388 | - * @return null|string |
|
| 389 | - * @since 30.0.0 |
|
| 390 | - */ |
|
| 391 | - final public function getWebhookMethod(): ?string { |
|
| 392 | - return $this->webhookMethod; |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - /** |
|
| 396 | - * @param string|null $webhookMethod |
|
| 397 | - * @return void |
|
| 398 | - * @since 30.0.0 |
|
| 399 | - */ |
|
| 400 | - final public function setWebhookMethod(?string $webhookMethod): void { |
|
| 401 | - $this->webhookMethod = $webhookMethod; |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - /** |
|
| 405 | - * @param int $status |
|
| 406 | - * @return 'STATUS_CANCELLED'|'STATUS_FAILED'|'STATUS_SUCCESSFUL'|'STATUS_RUNNING'|'STATUS_SCHEDULED'|'STATUS_UNKNOWN' |
|
| 407 | - * @since 30.0.0 |
|
| 408 | - */ |
|
| 409 | - final public static function statusToString(int $status): string { |
|
| 410 | - return match ($status) { |
|
| 411 | - self::STATUS_CANCELLED => 'STATUS_CANCELLED', |
|
| 412 | - self::STATUS_FAILED => 'STATUS_FAILED', |
|
| 413 | - self::STATUS_SUCCESSFUL => 'STATUS_SUCCESSFUL', |
|
| 414 | - self::STATUS_RUNNING => 'STATUS_RUNNING', |
|
| 415 | - self::STATUS_SCHEDULED => 'STATUS_SCHEDULED', |
|
| 416 | - default => 'STATUS_UNKNOWN', |
|
| 417 | - }; |
|
| 418 | - } |
|
| 419 | - |
|
| 420 | - /** |
|
| 421 | - * @since 33.0.0 |
|
| 422 | - */ |
|
| 423 | - public function setUserFacingErrorMessage(?string $userFacingErrorMessage): void { |
|
| 424 | - $this->userFacingErrorMessage = $userFacingErrorMessage; |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - /** |
|
| 428 | - * @since 33.0.0 |
|
| 429 | - */ |
|
| 430 | - public function getUserFacingErrorMessage(): ?string { |
|
| 431 | - return $this->userFacingErrorMessage; |
|
| 432 | - } |
|
| 21 | + protected ?int $id = null; |
|
| 22 | + |
|
| 23 | + protected ?DateTime $completionExpectedAt = null; |
|
| 24 | + |
|
| 25 | + protected ?array $output = null; |
|
| 26 | + |
|
| 27 | + protected ?string $errorMessage = null; |
|
| 28 | + |
|
| 29 | + protected ?float $progress = null; |
|
| 30 | + |
|
| 31 | + protected int $lastUpdated; |
|
| 32 | + |
|
| 33 | + protected ?string $webhookUri = null; |
|
| 34 | + |
|
| 35 | + protected ?string $webhookMethod = null; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @psalm-var self::STATUS_* |
|
| 39 | + */ |
|
| 40 | + protected int $status = self::STATUS_UNKNOWN; |
|
| 41 | + |
|
| 42 | + protected ?int $scheduledAt = null; |
|
| 43 | + |
|
| 44 | + protected ?int $startedAt = null; |
|
| 45 | + |
|
| 46 | + protected ?int $endedAt = null; |
|
| 47 | + |
|
| 48 | + protected bool $allowCleanup = true; |
|
| 49 | + |
|
| 50 | + protected ?string $userFacingErrorMessage = null; |
|
| 51 | + |
|
| 52 | + protected bool $includeWatermark = true; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * @since 30.0.0 |
|
| 56 | + */ |
|
| 57 | + public const STATUS_CANCELLED = 5; |
|
| 58 | + /** |
|
| 59 | + * @since 30.0.0 |
|
| 60 | + */ |
|
| 61 | + public const STATUS_FAILED = 4; |
|
| 62 | + /** |
|
| 63 | + * @since 30.0.0 |
|
| 64 | + */ |
|
| 65 | + public const STATUS_SUCCESSFUL = 3; |
|
| 66 | + /** |
|
| 67 | + * @since 30.0.0 |
|
| 68 | + */ |
|
| 69 | + public const STATUS_RUNNING = 2; |
|
| 70 | + /** |
|
| 71 | + * @since 30.0.0 |
|
| 72 | + */ |
|
| 73 | + public const STATUS_SCHEDULED = 1; |
|
| 74 | + /** |
|
| 75 | + * @since 30.0.0 |
|
| 76 | + */ |
|
| 77 | + public const STATUS_UNKNOWN = 0; |
|
| 78 | + |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * @param string $taskTypeId |
|
| 82 | + * @param array<string,list<numeric|string>|numeric|string> $input |
|
| 83 | + * @param string $appId |
|
| 84 | + * @param string|null $userId |
|
| 85 | + * @param null|string $customId An arbitrary customId for this task. max length: 255 chars |
|
| 86 | + * @since 30.0.0 |
|
| 87 | + */ |
|
| 88 | + final public function __construct( |
|
| 89 | + protected readonly string $taskTypeId, |
|
| 90 | + protected array $input, |
|
| 91 | + protected readonly string $appId, |
|
| 92 | + protected readonly ?string $userId, |
|
| 93 | + protected readonly ?string $customId = '', |
|
| 94 | + ) { |
|
| 95 | + $this->lastUpdated = time(); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * @since 30.0.0 |
|
| 100 | + */ |
|
| 101 | + final public function getTaskTypeId(): string { |
|
| 102 | + return $this->taskTypeId; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * @psalm-return self::STATUS_* |
|
| 107 | + * @since 30.0.0 |
|
| 108 | + */ |
|
| 109 | + final public function getStatus(): int { |
|
| 110 | + return $this->status; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * @psalm-param self::STATUS_* $status |
|
| 115 | + * @since 30.0.0 |
|
| 116 | + */ |
|
| 117 | + final public function setStatus(int $status): void { |
|
| 118 | + $this->status = $status; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * @param ?DateTime $at |
|
| 123 | + * @since 30.0.0 |
|
| 124 | + */ |
|
| 125 | + final public function setCompletionExpectedAt(?DateTime $at): void { |
|
| 126 | + $this->completionExpectedAt = $at; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * @return ?DateTime |
|
| 131 | + * @since 30.0.0 |
|
| 132 | + */ |
|
| 133 | + final public function getCompletionExpectedAt(): ?DateTime { |
|
| 134 | + return $this->completionExpectedAt; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * @return int|null |
|
| 139 | + * @since 30.0.0 |
|
| 140 | + */ |
|
| 141 | + final public function getId(): ?int { |
|
| 142 | + return $this->id; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * @param int|null $id |
|
| 147 | + * @since 30.0.0 |
|
| 148 | + */ |
|
| 149 | + final public function setId(?int $id): void { |
|
| 150 | + $this->id = $id; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * @param null|array<array-key, list<numeric|string>|numeric|string> $output |
|
| 155 | + * @since 30.0.0 |
|
| 156 | + */ |
|
| 157 | + final public function setOutput(?array $output): void { |
|
| 158 | + $this->output = $output; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * @return array<array-key, list<numeric|string>|numeric|string>|null |
|
| 163 | + * @since 30.0.0 |
|
| 164 | + */ |
|
| 165 | + final public function getOutput(): ?array { |
|
| 166 | + return $this->output; |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * @return array<array-key, list<numeric|string>|numeric|string> |
|
| 171 | + * @since 30.0.0 |
|
| 172 | + */ |
|
| 173 | + final public function getInput(): array { |
|
| 174 | + return $this->input; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * @return string |
|
| 179 | + * @since 30.0.0 |
|
| 180 | + */ |
|
| 181 | + final public function getAppId(): string { |
|
| 182 | + return $this->appId; |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * @return null|string |
|
| 187 | + * @since 30.0.0 |
|
| 188 | + */ |
|
| 189 | + final public function getCustomId(): ?string { |
|
| 190 | + return $this->customId; |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * @return string|null |
|
| 195 | + * @since 30.0.0 |
|
| 196 | + */ |
|
| 197 | + final public function getUserId(): ?string { |
|
| 198 | + return $this->userId; |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + /** |
|
| 202 | + * @return int |
|
| 203 | + * @since 30.0.0 |
|
| 204 | + */ |
|
| 205 | + final public function getLastUpdated(): int { |
|
| 206 | + return $this->lastUpdated; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * @param int $lastUpdated |
|
| 211 | + * @since 30.0.0 |
|
| 212 | + */ |
|
| 213 | + final public function setLastUpdated(int $lastUpdated): void { |
|
| 214 | + $this->lastUpdated = $lastUpdated; |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * @return int|null |
|
| 219 | + * @since 30.0.0 |
|
| 220 | + */ |
|
| 221 | + final public function getScheduledAt(): ?int { |
|
| 222 | + return $this->scheduledAt; |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + /** |
|
| 226 | + * @param int|null $scheduledAt |
|
| 227 | + * @since 30.0.0 |
|
| 228 | + */ |
|
| 229 | + final public function setScheduledAt(?int $scheduledAt): void { |
|
| 230 | + $this->scheduledAt = $scheduledAt; |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * @return int|null |
|
| 235 | + * @since 30.0.0 |
|
| 236 | + */ |
|
| 237 | + final public function getStartedAt(): ?int { |
|
| 238 | + return $this->startedAt; |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + /** |
|
| 242 | + * @param int|null $startedAt |
|
| 243 | + * @since 30.0.0 |
|
| 244 | + */ |
|
| 245 | + final public function setStartedAt(?int $startedAt): void { |
|
| 246 | + $this->startedAt = $startedAt; |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * @return int|null |
|
| 251 | + * @since 30.0.0 |
|
| 252 | + */ |
|
| 253 | + final public function getEndedAt(): ?int { |
|
| 254 | + return $this->endedAt; |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + /** |
|
| 258 | + * @param int|null $endedAt |
|
| 259 | + * @since 30.0.0 |
|
| 260 | + */ |
|
| 261 | + final public function setEndedAt(?int $endedAt): void { |
|
| 262 | + $this->endedAt = $endedAt; |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + /** |
|
| 266 | + * @return bool |
|
| 267 | + * @since 32.0.0 |
|
| 268 | + */ |
|
| 269 | + final public function getAllowCleanup(): bool { |
|
| 270 | + return $this->allowCleanup; |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + /** |
|
| 274 | + * @param bool $allowCleanup |
|
| 275 | + * @since 32.0.0 |
|
| 276 | + */ |
|
| 277 | + final public function setAllowCleanup(bool $allowCleanup): void { |
|
| 278 | + $this->allowCleanup = $allowCleanup; |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + /** |
|
| 282 | + * @return bool |
|
| 283 | + * @since 33.0.0 |
|
| 284 | + */ |
|
| 285 | + final public function getIncludeWatermark(): bool { |
|
| 286 | + return $this->includeWatermark; |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + /** |
|
| 290 | + * @param bool $includeWatermark |
|
| 291 | + * @since 33.0.0 |
|
| 292 | + */ |
|
| 293 | + final public function setIncludeWatermark(bool $includeWatermark): void { |
|
| 294 | + $this->includeWatermark = $includeWatermark; |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + /** |
|
| 298 | + * @psalm-return array{id: int, lastUpdated: int, type: string, status: 'STATUS_CANCELLED'|'STATUS_FAILED'|'STATUS_SUCCESSFUL'|'STATUS_RUNNING'|'STATUS_SCHEDULED'|'STATUS_UNKNOWN', userId: ?string, appId: string, input: array<string, list<numeric|string>|numeric|string>, output: ?array<string, list<numeric|string>|numeric|string>, customId: ?string, completionExpectedAt: ?int, progress: ?float, scheduledAt: ?int, startedAt: ?int, endedAt: ?int, allowCleanup: bool, includeWatermark: bool, userFacingErrorMessage: ?string} |
|
| 299 | + * @since 30.0.0 |
|
| 300 | + */ |
|
| 301 | + final public function jsonSerialize(): array { |
|
| 302 | + return [ |
|
| 303 | + 'id' => (int)$this->getId(), |
|
| 304 | + 'type' => $this->getTaskTypeId(), |
|
| 305 | + 'lastUpdated' => $this->getLastUpdated(), |
|
| 306 | + 'status' => self::statusToString($this->getStatus()), |
|
| 307 | + 'userId' => $this->getUserId(), |
|
| 308 | + 'appId' => $this->getAppId(), |
|
| 309 | + 'input' => $this->getInput(), |
|
| 310 | + 'output' => $this->getOutput(), |
|
| 311 | + 'customId' => $this->getCustomId(), |
|
| 312 | + 'completionExpectedAt' => $this->getCompletionExpectedAt()?->getTimestamp(), |
|
| 313 | + 'progress' => $this->getProgress(), |
|
| 314 | + 'scheduledAt' => $this->getScheduledAt(), |
|
| 315 | + 'startedAt' => $this->getStartedAt(), |
|
| 316 | + 'endedAt' => $this->getEndedAt(), |
|
| 317 | + 'allowCleanup' => $this->getAllowCleanup(), |
|
| 318 | + 'includeWatermark' => $this->getIncludeWatermark(), |
|
| 319 | + 'userFacingErrorMessage' => $this->getUserFacingErrorMessage(), |
|
| 320 | + ]; |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + /** |
|
| 324 | + * @param string|null $error |
|
| 325 | + * @return void |
|
| 326 | + * @since 30.0.0 |
|
| 327 | + */ |
|
| 328 | + final public function setErrorMessage(?string $error) { |
|
| 329 | + $this->errorMessage = $error; |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + /** |
|
| 333 | + * @return string|null |
|
| 334 | + * @since 30.0.0 |
|
| 335 | + */ |
|
| 336 | + final public function getErrorMessage(): ?string { |
|
| 337 | + return $this->errorMessage; |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + /** |
|
| 341 | + * @param array $input |
|
| 342 | + * @return void |
|
| 343 | + * @since 30.0.0 |
|
| 344 | + */ |
|
| 345 | + final public function setInput(array $input): void { |
|
| 346 | + $this->input = $input; |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + /** |
|
| 350 | + * @param float|null $progress |
|
| 351 | + * @return void |
|
| 352 | + * @throws ValidationException |
|
| 353 | + * @since 30.0.0 |
|
| 354 | + */ |
|
| 355 | + final public function setProgress(?float $progress): void { |
|
| 356 | + if ($progress < 0 || $progress > 1.0) { |
|
| 357 | + throw new ValidationException('Progress must be between 0.0 and 1.0 inclusively; ' . $progress . ' given'); |
|
| 358 | + } |
|
| 359 | + $this->progress = $progress; |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + /** |
|
| 363 | + * @return float|null |
|
| 364 | + * @since 30.0.0 |
|
| 365 | + */ |
|
| 366 | + final public function getProgress(): ?float { |
|
| 367 | + return $this->progress; |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + /** |
|
| 371 | + * @return null|string |
|
| 372 | + * @since 30.0.0 |
|
| 373 | + */ |
|
| 374 | + final public function getWebhookUri(): ?string { |
|
| 375 | + return $this->webhookUri; |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + /** |
|
| 379 | + * @param string|null $webhookUri |
|
| 380 | + * @return void |
|
| 381 | + * @since 30.0.0 |
|
| 382 | + */ |
|
| 383 | + final public function setWebhookUri(?string $webhookUri): void { |
|
| 384 | + $this->webhookUri = $webhookUri; |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + /** |
|
| 388 | + * @return null|string |
|
| 389 | + * @since 30.0.0 |
|
| 390 | + */ |
|
| 391 | + final public function getWebhookMethod(): ?string { |
|
| 392 | + return $this->webhookMethod; |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + /** |
|
| 396 | + * @param string|null $webhookMethod |
|
| 397 | + * @return void |
|
| 398 | + * @since 30.0.0 |
|
| 399 | + */ |
|
| 400 | + final public function setWebhookMethod(?string $webhookMethod): void { |
|
| 401 | + $this->webhookMethod = $webhookMethod; |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + /** |
|
| 405 | + * @param int $status |
|
| 406 | + * @return 'STATUS_CANCELLED'|'STATUS_FAILED'|'STATUS_SUCCESSFUL'|'STATUS_RUNNING'|'STATUS_SCHEDULED'|'STATUS_UNKNOWN' |
|
| 407 | + * @since 30.0.0 |
|
| 408 | + */ |
|
| 409 | + final public static function statusToString(int $status): string { |
|
| 410 | + return match ($status) { |
|
| 411 | + self::STATUS_CANCELLED => 'STATUS_CANCELLED', |
|
| 412 | + self::STATUS_FAILED => 'STATUS_FAILED', |
|
| 413 | + self::STATUS_SUCCESSFUL => 'STATUS_SUCCESSFUL', |
|
| 414 | + self::STATUS_RUNNING => 'STATUS_RUNNING', |
|
| 415 | + self::STATUS_SCHEDULED => 'STATUS_SCHEDULED', |
|
| 416 | + default => 'STATUS_UNKNOWN', |
|
| 417 | + }; |
|
| 418 | + } |
|
| 419 | + |
|
| 420 | + /** |
|
| 421 | + * @since 33.0.0 |
|
| 422 | + */ |
|
| 423 | + public function setUserFacingErrorMessage(?string $userFacingErrorMessage): void { |
|
| 424 | + $this->userFacingErrorMessage = $userFacingErrorMessage; |
|
| 425 | + } |
|
| 426 | + |
|
| 427 | + /** |
|
| 428 | + * @since 33.0.0 |
|
| 429 | + */ |
|
| 430 | + public function getUserFacingErrorMessage(): ?string { |
|
| 431 | + return $this->userFacingErrorMessage; |
|
| 432 | + } |
|
| 433 | 433 | } |