DeleteObjectRequest.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <?php
  2. namespace AsyncAws\S3\Input;
  3. use AsyncAws\Core\Exception\InvalidArgument;
  4. use AsyncAws\Core\Input;
  5. use AsyncAws\Core\Request;
  6. use AsyncAws\Core\Stream\StreamFactory;
  7. use AsyncAws\S3\Enum\RequestPayer;
  8. final class DeleteObjectRequest extends Input
  9. {
  10. /**
  11. * The bucket name of the bucket containing the object.
  12. *
  13. * When using this action with an access point, you must direct requests to the access point hostname. The access point
  14. * hostname takes the form *AccessPointName*-*AccountId*.s3-accesspoint.*Region*.amazonaws.com. When using this action
  15. * with an access point through the Amazon Web Services SDKs, you provide the access point ARN in place of the bucket
  16. * name. For more information about access point ARNs, see Using access points [^1] in the *Amazon S3 User Guide*.
  17. *
  18. * When you use this action with Amazon S3 on Outposts, you must direct requests to the S3 on Outposts hostname. The S3
  19. * on Outposts hostname takes the form `*AccessPointName*-*AccountId*.*outpostID*.s3-outposts.*Region*.amazonaws.com`.
  20. * When you use this action with S3 on Outposts through the Amazon Web Services SDKs, you provide the Outposts access
  21. * point ARN in place of the bucket name. For more information about S3 on Outposts ARNs, see What is S3 on Outposts
  22. * [^2] in the *Amazon S3 User Guide*.
  23. *
  24. * [^1]: https://docs.aws.amazon.com/AmazonS3/latest/userguide/using-access-points.html
  25. * [^2]: https://docs.aws.amazon.com/AmazonS3/latest/userguide/S3onOutposts.html
  26. *
  27. * @required
  28. *
  29. * @var string|null
  30. */
  31. private $bucket;
  32. /**
  33. * Key name of the object to delete.
  34. *
  35. * @required
  36. *
  37. * @var string|null
  38. */
  39. private $key;
  40. /**
  41. * The concatenation of the authentication device's serial number, a space, and the value that is displayed on your
  42. * authentication device. Required to permanently delete a versioned object if versioning is configured with MFA delete
  43. * enabled.
  44. *
  45. * @var string|null
  46. */
  47. private $mfa;
  48. /**
  49. * VersionId used to reference a specific version of the object.
  50. *
  51. * @var string|null
  52. */
  53. private $versionId;
  54. /**
  55. * @var RequestPayer::*|null
  56. */
  57. private $requestPayer;
  58. /**
  59. * Indicates whether S3 Object Lock should bypass Governance-mode restrictions to process this operation. To use this
  60. * header, you must have the `s3:BypassGovernanceRetention` permission.
  61. *
  62. * @var bool|null
  63. */
  64. private $bypassGovernanceRetention;
  65. /**
  66. * The account ID of the expected bucket owner. If the bucket is owned by a different account, the request fails with
  67. * the HTTP status code `403 Forbidden` (access denied).
  68. *
  69. * @var string|null
  70. */
  71. private $expectedBucketOwner;
  72. /**
  73. * @param array{
  74. * Bucket?: string,
  75. * Key?: string,
  76. * MFA?: string,
  77. * VersionId?: string,
  78. * RequestPayer?: RequestPayer::*,
  79. * BypassGovernanceRetention?: bool,
  80. * ExpectedBucketOwner?: string,
  81. *
  82. * @region?: string,
  83. * } $input
  84. */
  85. public function __construct(array $input = [])
  86. {
  87. $this->bucket = $input['Bucket'] ?? null;
  88. $this->key = $input['Key'] ?? null;
  89. $this->mfa = $input['MFA'] ?? null;
  90. $this->versionId = $input['VersionId'] ?? null;
  91. $this->requestPayer = $input['RequestPayer'] ?? null;
  92. $this->bypassGovernanceRetention = $input['BypassGovernanceRetention'] ?? null;
  93. $this->expectedBucketOwner = $input['ExpectedBucketOwner'] ?? null;
  94. parent::__construct($input);
  95. }
  96. public static function create($input): self
  97. {
  98. return $input instanceof self ? $input : new self($input);
  99. }
  100. public function getBucket(): ?string
  101. {
  102. return $this->bucket;
  103. }
  104. public function getBypassGovernanceRetention(): ?bool
  105. {
  106. return $this->bypassGovernanceRetention;
  107. }
  108. public function getExpectedBucketOwner(): ?string
  109. {
  110. return $this->expectedBucketOwner;
  111. }
  112. public function getKey(): ?string
  113. {
  114. return $this->key;
  115. }
  116. public function getMfa(): ?string
  117. {
  118. return $this->mfa;
  119. }
  120. /**
  121. * @return RequestPayer::*|null
  122. */
  123. public function getRequestPayer(): ?string
  124. {
  125. return $this->requestPayer;
  126. }
  127. public function getVersionId(): ?string
  128. {
  129. return $this->versionId;
  130. }
  131. /**
  132. * @internal
  133. */
  134. public function request(): Request
  135. {
  136. // Prepare headers
  137. $headers = ['content-type' => 'application/xml'];
  138. if (null !== $this->mfa) {
  139. $headers['x-amz-mfa'] = $this->mfa;
  140. }
  141. if (null !== $this->requestPayer) {
  142. if (!RequestPayer::exists($this->requestPayer)) {
  143. throw new InvalidArgument(sprintf('Invalid parameter "RequestPayer" for "%s". The value "%s" is not a valid "RequestPayer".', __CLASS__, $this->requestPayer));
  144. }
  145. $headers['x-amz-request-payer'] = $this->requestPayer;
  146. }
  147. if (null !== $this->bypassGovernanceRetention) {
  148. $headers['x-amz-bypass-governance-retention'] = $this->bypassGovernanceRetention ? 'true' : 'false';
  149. }
  150. if (null !== $this->expectedBucketOwner) {
  151. $headers['x-amz-expected-bucket-owner'] = $this->expectedBucketOwner;
  152. }
  153. // Prepare query
  154. $query = [];
  155. if (null !== $this->versionId) {
  156. $query['versionId'] = $this->versionId;
  157. }
  158. // Prepare URI
  159. $uri = [];
  160. if (null === $v = $this->bucket) {
  161. throw new InvalidArgument(sprintf('Missing parameter "Bucket" for "%s". The value cannot be null.', __CLASS__));
  162. }
  163. $uri['Bucket'] = $v;
  164. if (null === $v = $this->key) {
  165. throw new InvalidArgument(sprintf('Missing parameter "Key" for "%s". The value cannot be null.', __CLASS__));
  166. }
  167. $uri['Key'] = $v;
  168. $uriString = '/' . rawurlencode($uri['Bucket']) . '/' . str_replace('%2F', '/', rawurlencode($uri['Key']));
  169. // Prepare Body
  170. $body = '';
  171. // Return the Request
  172. return new Request('DELETE', $uriString, $query, $headers, StreamFactory::create($body));
  173. }
  174. public function setBucket(?string $value): self
  175. {
  176. $this->bucket = $value;
  177. return $this;
  178. }
  179. public function setBypassGovernanceRetention(?bool $value): self
  180. {
  181. $this->bypassGovernanceRetention = $value;
  182. return $this;
  183. }
  184. public function setExpectedBucketOwner(?string $value): self
  185. {
  186. $this->expectedBucketOwner = $value;
  187. return $this;
  188. }
  189. public function setKey(?string $value): self
  190. {
  191. $this->key = $value;
  192. return $this;
  193. }
  194. public function setMfa(?string $value): self
  195. {
  196. $this->mfa = $value;
  197. return $this;
  198. }
  199. /**
  200. * @param RequestPayer::*|null $value
  201. */
  202. public function setRequestPayer(?string $value): self
  203. {
  204. $this->requestPayer = $value;
  205. return $this;
  206. }
  207. public function setVersionId(?string $value): self
  208. {
  209. $this->versionId = $value;
  210. return $this;
  211. }
  212. }