DeleteBucketRequest.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. final class DeleteBucketRequest extends Input
  8. {
  9. /**
  10. * Specifies the bucket being deleted.
  11. *
  12. * @required
  13. *
  14. * @var string|null
  15. */
  16. private $bucket;
  17. /**
  18. * The account ID of the expected bucket owner. If the bucket is owned by a different account, the request fails with
  19. * the HTTP status code `403 Forbidden` (access denied).
  20. *
  21. * @var string|null
  22. */
  23. private $expectedBucketOwner;
  24. /**
  25. * @param array{
  26. * Bucket?: string,
  27. * ExpectedBucketOwner?: string,
  28. *
  29. * @region?: string,
  30. * } $input
  31. */
  32. public function __construct(array $input = [])
  33. {
  34. $this->bucket = $input['Bucket'] ?? null;
  35. $this->expectedBucketOwner = $input['ExpectedBucketOwner'] ?? null;
  36. parent::__construct($input);
  37. }
  38. public static function create($input): self
  39. {
  40. return $input instanceof self ? $input : new self($input);
  41. }
  42. public function getBucket(): ?string
  43. {
  44. return $this->bucket;
  45. }
  46. public function getExpectedBucketOwner(): ?string
  47. {
  48. return $this->expectedBucketOwner;
  49. }
  50. /**
  51. * @internal
  52. */
  53. public function request(): Request
  54. {
  55. // Prepare headers
  56. $headers = ['content-type' => 'application/xml'];
  57. if (null !== $this->expectedBucketOwner) {
  58. $headers['x-amz-expected-bucket-owner'] = $this->expectedBucketOwner;
  59. }
  60. // Prepare query
  61. $query = [];
  62. // Prepare URI
  63. $uri = [];
  64. if (null === $v = $this->bucket) {
  65. throw new InvalidArgument(sprintf('Missing parameter "Bucket" for "%s". The value cannot be null.', __CLASS__));
  66. }
  67. $uri['Bucket'] = $v;
  68. $uriString = '/' . rawurlencode($uri['Bucket']);
  69. // Prepare Body
  70. $body = '';
  71. // Return the Request
  72. return new Request('DELETE', $uriString, $query, $headers, StreamFactory::create($body));
  73. }
  74. public function setBucket(?string $value): self
  75. {
  76. $this->bucket = $value;
  77. return $this;
  78. }
  79. public function setExpectedBucketOwner(?string $value): self
  80. {
  81. $this->expectedBucketOwner = $value;
  82. return $this;
  83. }
  84. }