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