|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace AsyncAws\S3\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 | +use AsyncAws\S3\Enum\ChecksumAlgorithm; |
| 10 | +use AsyncAws\S3\ValueObject\Tag; |
| 11 | +use AsyncAws\S3\ValueObject\Tagging; |
| 12 | + |
| 13 | +final class PutBucketTaggingRequest extends Input |
| 14 | +{ |
| 15 | + /** |
| 16 | + * The bucket name. |
| 17 | + * |
| 18 | + * @required |
| 19 | + * |
| 20 | + * @var string|null |
| 21 | + */ |
| 22 | + private $bucket; |
| 23 | + |
| 24 | + /** |
| 25 | + * The base64-encoded 128-bit MD5 digest of the data. You must use this header as a message integrity check to verify |
| 26 | + * that the request body was not corrupted in transit. For more information, see RFC 1864 [^1]. |
| 27 | + * |
| 28 | + * For requests made using the Amazon Web Services Command Line Interface (CLI) or Amazon Web Services SDKs, this field |
| 29 | + * is calculated automatically. |
| 30 | + * |
| 31 | + * [^1]: http://www.ietf.org/rfc/rfc1864.txt |
| 32 | + * |
| 33 | + * @var string|null |
| 34 | + */ |
| 35 | + private $contentMd5; |
| 36 | + |
| 37 | + /** |
| 38 | + * Indicates the algorithm used to create the checksum for the object when using the SDK. This header will not provide |
| 39 | + * any additional functionality if not using the SDK. When sending this header, there must be a corresponding |
| 40 | + * `x-amz-checksum` or `x-amz-trailer` header sent. Otherwise, Amazon S3 fails the request with the HTTP status code |
| 41 | + * `400 Bad Request`. For more information, see Checking object integrity [^1] in the *Amazon S3 User Guide*. |
| 42 | + * |
| 43 | + * If you provide an individual checksum, Amazon S3 ignores any provided `ChecksumAlgorithm` parameter. |
| 44 | + * |
| 45 | + * [^1]: https://docs.aws.amazon.com/AmazonS3/latest/userguide/checking-object-integrity.html |
| 46 | + * |
| 47 | + * @var ChecksumAlgorithm::*|null |
| 48 | + */ |
| 49 | + private $checksumAlgorithm; |
| 50 | + |
| 51 | + /** |
| 52 | + * Container for the `TagSet` and `Tag` elements. |
| 53 | + * |
| 54 | + * @required |
| 55 | + * |
| 56 | + * @var Tagging|null |
| 57 | + */ |
| 58 | + private $tagging; |
| 59 | + |
| 60 | + /** |
| 61 | + * The account ID of the expected bucket owner. If the bucket is owned by a different account, the request fails with |
| 62 | + * the HTTP status code `403 Forbidden` (access denied). |
| 63 | + * |
| 64 | + * @var string|null |
| 65 | + */ |
| 66 | + private $expectedBucketOwner; |
| 67 | + |
| 68 | + /** |
| 69 | + * @param array{ |
| 70 | + * Bucket?: string, |
| 71 | + * ContentMD5?: string, |
| 72 | + * ChecksumAlgorithm?: ChecksumAlgorithm::*, |
| 73 | + * Tagging?: Tagging|array, |
| 74 | + * ExpectedBucketOwner?: string, |
| 75 | + * |
| 76 | + * @region?: string, |
| 77 | + * } $input |
| 78 | + */ |
| 79 | + public function __construct(array $input = []) |
| 80 | + { |
| 81 | + $this->bucket = $input['Bucket'] ?? null; |
| 82 | + $this->contentMd5 = $input['ContentMD5'] ?? null; |
| 83 | + $this->checksumAlgorithm = $input['ChecksumAlgorithm'] ?? null; |
| 84 | + $this->tagging = isset($input['Tagging']) ? Tagging::create($input['Tagging']) : null; |
| 85 | + $this->expectedBucketOwner = $input['ExpectedBucketOwner'] ?? null; |
| 86 | + parent::__construct($input); |
| 87 | + } |
| 88 | + |
| 89 | + public static function create($input): self |
| 90 | + { |
| 91 | + return $input instanceof self ? $input : new self($input); |
| 92 | + } |
| 93 | + |
| 94 | + public function getBucket(): ?string |
| 95 | + { |
| 96 | + return $this->bucket; |
| 97 | + } |
| 98 | + |
| 99 | + /** |
| 100 | + * @return ChecksumAlgorithm::*|null |
| 101 | + */ |
| 102 | + public function getChecksumAlgorithm(): ?string |
| 103 | + { |
| 104 | + return $this->checksumAlgorithm; |
| 105 | + } |
| 106 | + |
| 107 | + public function getContentMd5(): ?string |
| 108 | + { |
| 109 | + return $this->contentMd5; |
| 110 | + } |
| 111 | + |
| 112 | + public function getExpectedBucketOwner(): ?string |
| 113 | + { |
| 114 | + return $this->expectedBucketOwner; |
| 115 | + } |
| 116 | + |
| 117 | + public function getTagging(): ?Tagging |
| 118 | + { |
| 119 | + return $this->tagging; |
| 120 | + } |
| 121 | + |
| 122 | + /** |
| 123 | + * @internal |
| 124 | + */ |
| 125 | + public function request(): Request |
| 126 | + { |
| 127 | + // Prepare headers |
| 128 | + $headers = ['content-type' => 'application/xml']; |
| 129 | + if (null !== $this->contentMd5) { |
| 130 | + $headers['Content-MD5'] = $this->contentMd5; |
| 131 | + } |
| 132 | + if (null !== $this->checksumAlgorithm) { |
| 133 | + if (!ChecksumAlgorithm::exists($this->checksumAlgorithm)) { |
| 134 | + throw new InvalidArgument(sprintf('Invalid parameter "ChecksumAlgorithm" for "%s". The value "%s" is not a valid "ChecksumAlgorithm".', __CLASS__, $this->checksumAlgorithm)); |
| 135 | + } |
| 136 | + $headers['x-amz-sdk-checksum-algorithm'] = $this->checksumAlgorithm; |
| 137 | + } |
| 138 | + if (null !== $this->expectedBucketOwner) { |
| 139 | + $headers['x-amz-expected-bucket-owner'] = $this->expectedBucketOwner; |
| 140 | + } |
| 141 | + |
| 142 | + // Prepare query |
| 143 | + $query = []; |
| 144 | + |
| 145 | + // Prepare URI |
| 146 | + $uri = []; |
| 147 | + if (null === $v = $this->bucket) { |
| 148 | + throw new InvalidArgument(sprintf('Missing parameter "Bucket" for "%s". The value cannot be null.', __CLASS__)); |
| 149 | + } |
| 150 | + $uri['Bucket'] = $v; |
| 151 | + $uriString = '/' . rawurlencode($uri['Bucket']) . '?tagging'; |
| 152 | + |
| 153 | + // Prepare Body |
| 154 | + |
| 155 | + $document = new \DOMDocument('1.0', 'UTF-8'); |
| 156 | + $document->formatOutput = false; |
| 157 | + $this->requestBody($document, $document); |
| 158 | + $body = $document->hasChildNodes() ? $document->saveXML() : ''; |
| 159 | + |
| 160 | + // Return the Request |
| 161 | + return new Request('PUT', $uriString, $query, $headers, StreamFactory::create($body)); |
| 162 | + } |
| 163 | + |
| 164 | + public function setBucket(?string $value): self |
| 165 | + { |
| 166 | + $this->bucket = $value; |
| 167 | + |
| 168 | + return $this; |
| 169 | + } |
| 170 | + |
| 171 | + /** |
| 172 | + * @param ChecksumAlgorithm::*|null $value |
| 173 | + */ |
| 174 | + public function setChecksumAlgorithm(?string $value): self |
| 175 | + { |
| 176 | + $this->checksumAlgorithm = $value; |
| 177 | + |
| 178 | + return $this; |
| 179 | + } |
| 180 | + |
| 181 | + public function setContentMd5(?string $value): self |
| 182 | + { |
| 183 | + $this->contentMd5 = $value; |
| 184 | + |
| 185 | + return $this; |
| 186 | + } |
| 187 | + |
| 188 | + public function setExpectedBucketOwner(?string $value): self |
| 189 | + { |
| 190 | + $this->expectedBucketOwner = $value; |
| 191 | + |
| 192 | + return $this; |
| 193 | + } |
| 194 | + |
| 195 | + public function setTagging(?Tagging $value): self |
| 196 | + { |
| 197 | + $this->tagging = $value; |
| 198 | + |
| 199 | + return $this; |
| 200 | + } |
| 201 | + |
| 202 | + private function requestBody(\DOMNode $node, \DOMDocument $document): void |
| 203 | + { |
| 204 | + if (null === $v = $this->tagging) { |
| 205 | + throw new InvalidArgument(sprintf('Missing parameter "Tagging" for "%s". The value cannot be null.', __CLASS__)); |
| 206 | + } |
| 207 | + |
| 208 | + $node->appendChild($child = $document->createElement('Tagging')); |
| 209 | + $child->setAttribute('xmlns', 'http://s3.amazonaws.com/doc/2006-03-01/'); |
| 210 | + $v->requestBody($child, $document); |
| 211 | + } |
| 212 | +} |
0 commit comments