|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace AsyncAws\StepFunctions\Input; |
| 4 | + |
| 5 | +use AsyncAws\Core\Exception\InvalidArgument; |
| 6 | +use AsyncAws\Core\Input; |
| 7 | +use AsyncAws\Core\Request; |
| 8 | +use AsyncAws\Core\Stream\StreamFactory; |
| 9 | + |
| 10 | +final class SendTaskFailureInput extends Input |
| 11 | +{ |
| 12 | + /** |
| 13 | + * The token that represents this task. Task tokens are generated by Step Functions when tasks are assigned to a worker, |
| 14 | + * or in the context object when a workflow enters a task state. See GetActivityTaskOutput$taskToken. |
| 15 | + * |
| 16 | + * @see https://docs.aws.amazon.com/step-functions/latest/dg/input-output-contextobject.html |
| 17 | + * @required |
| 18 | + * |
| 19 | + * @var string|null |
| 20 | + */ |
| 21 | + private $taskToken; |
| 22 | + |
| 23 | + /** |
| 24 | + * The error code of the failure. |
| 25 | + * |
| 26 | + * @var string|null |
| 27 | + */ |
| 28 | + private $error; |
| 29 | + |
| 30 | + /** |
| 31 | + * A more detailed explanation of the cause of the failure. |
| 32 | + * |
| 33 | + * @var string|null |
| 34 | + */ |
| 35 | + private $cause; |
| 36 | + |
| 37 | + /** |
| 38 | + * @param array{ |
| 39 | + * taskToken?: string, |
| 40 | + * error?: string, |
| 41 | + * cause?: string, |
| 42 | + * @region?: string, |
| 43 | + * } $input |
| 44 | + */ |
| 45 | + public function __construct(array $input = []) |
| 46 | + { |
| 47 | + $this->taskToken = $input['taskToken'] ?? null; |
| 48 | + $this->error = $input['error'] ?? null; |
| 49 | + $this->cause = $input['cause'] ?? null; |
| 50 | + parent::__construct($input); |
| 51 | + } |
| 52 | + |
| 53 | + public static function create($input): self |
| 54 | + { |
| 55 | + return $input instanceof self ? $input : new self($input); |
| 56 | + } |
| 57 | + |
| 58 | + public function getCause(): ?string |
| 59 | + { |
| 60 | + return $this->cause; |
| 61 | + } |
| 62 | + |
| 63 | + public function getError(): ?string |
| 64 | + { |
| 65 | + return $this->error; |
| 66 | + } |
| 67 | + |
| 68 | + public function getTaskToken(): ?string |
| 69 | + { |
| 70 | + return $this->taskToken; |
| 71 | + } |
| 72 | + |
| 73 | + /** |
| 74 | + * @internal |
| 75 | + */ |
| 76 | + public function request(): Request |
| 77 | + { |
| 78 | + // Prepare headers |
| 79 | + $headers = [ |
| 80 | + 'Content-Type' => 'application/x-amz-json-1.0', |
| 81 | + 'X-Amz-Target' => 'AWSStepFunctions.SendTaskFailure', |
| 82 | + ]; |
| 83 | + |
| 84 | + // Prepare query |
| 85 | + $query = []; |
| 86 | + |
| 87 | + // Prepare URI |
| 88 | + $uriString = '/'; |
| 89 | + |
| 90 | + // Prepare Body |
| 91 | + $bodyPayload = $this->requestBody(); |
| 92 | + $body = empty($bodyPayload) ? '{}' : json_encode($bodyPayload, 4194304); |
| 93 | + |
| 94 | + // Return the Request |
| 95 | + return new Request('POST', $uriString, $query, $headers, StreamFactory::create($body)); |
| 96 | + } |
| 97 | + |
| 98 | + public function setCause(?string $value): self |
| 99 | + { |
| 100 | + $this->cause = $value; |
| 101 | + |
| 102 | + return $this; |
| 103 | + } |
| 104 | + |
| 105 | + public function setError(?string $value): self |
| 106 | + { |
| 107 | + $this->error = $value; |
| 108 | + |
| 109 | + return $this; |
| 110 | + } |
| 111 | + |
| 112 | + public function setTaskToken(?string $value): self |
| 113 | + { |
| 114 | + $this->taskToken = $value; |
| 115 | + |
| 116 | + return $this; |
| 117 | + } |
| 118 | + |
| 119 | + private function requestBody(): array |
| 120 | + { |
| 121 | + $payload = []; |
| 122 | + if (null === $v = $this->taskToken) { |
| 123 | + throw new InvalidArgument(sprintf('Missing parameter "taskToken" for "%s". The value cannot be null.', __CLASS__)); |
| 124 | + } |
| 125 | + $payload['taskToken'] = $v; |
| 126 | + if (null !== $v = $this->error) { |
| 127 | + $payload['error'] = $v; |
| 128 | + } |
| 129 | + if (null !== $v = $this->cause) { |
| 130 | + $payload['cause'] = $v; |
| 131 | + } |
| 132 | + |
| 133 | + return $payload; |
| 134 | + } |
| 135 | +} |
0 commit comments