ListObjectsV2Request.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  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\EncodingType;
  8. use AsyncAws\S3\Enum\RequestPayer;
  9. final class ListObjectsV2Request extends Input
  10. {
  11. /**
  12. * Bucket name to list.
  13. *
  14. * When using this action with an access point, you must direct requests to the access point hostname. The access point
  15. * hostname takes the form *AccessPointName*-*AccountId*.s3-accesspoint.*Region*.amazonaws.com. When using this action
  16. * with an access point through the Amazon Web Services SDKs, you provide the access point ARN in place of the bucket
  17. * name. For more information about access point ARNs, see Using access points [^1] in the *Amazon S3 User Guide*.
  18. *
  19. * When you use this action with Amazon S3 on Outposts, you must direct requests to the S3 on Outposts hostname. The S3
  20. * on Outposts hostname takes the form `*AccessPointName*-*AccountId*.*outpostID*.s3-outposts.*Region*.amazonaws.com`.
  21. * When you use this action with S3 on Outposts through the Amazon Web Services SDKs, you provide the Outposts access
  22. * point ARN in place of the bucket name. For more information about S3 on Outposts ARNs, see What is S3 on Outposts
  23. * [^2] in the *Amazon S3 User Guide*.
  24. *
  25. * [^1]: https://docs.aws.amazon.com/AmazonS3/latest/userguide/using-access-points.html
  26. * [^2]: https://docs.aws.amazon.com/AmazonS3/latest/userguide/S3onOutposts.html
  27. *
  28. * @required
  29. *
  30. * @var string|null
  31. */
  32. private $bucket;
  33. /**
  34. * A delimiter is a character you use to group keys.
  35. *
  36. * @var string|null
  37. */
  38. private $delimiter;
  39. /**
  40. * Encoding type used by Amazon S3 to encode object keys in the response.
  41. *
  42. * @var EncodingType::*|null
  43. */
  44. private $encodingType;
  45. /**
  46. * Sets the maximum number of keys returned in the response. By default the action returns up to 1,000 key names. The
  47. * response might contain fewer keys but will never contain more.
  48. *
  49. * @var int|null
  50. */
  51. private $maxKeys;
  52. /**
  53. * Limits the response to keys that begin with the specified prefix.
  54. *
  55. * @var string|null
  56. */
  57. private $prefix;
  58. /**
  59. * ContinuationToken indicates Amazon S3 that the list is being continued on this bucket with a token. ContinuationToken
  60. * is obfuscated and is not a real key.
  61. *
  62. * @var string|null
  63. */
  64. private $continuationToken;
  65. /**
  66. * The owner field is not present in listV2 by default, if you want to return owner field with each key in the result
  67. * then set the fetch owner field to true.
  68. *
  69. * @var bool|null
  70. */
  71. private $fetchOwner;
  72. /**
  73. * StartAfter is where you want Amazon S3 to start listing from. Amazon S3 starts listing after this specified key.
  74. * StartAfter can be any key in the bucket.
  75. *
  76. * @var string|null
  77. */
  78. private $startAfter;
  79. /**
  80. * Confirms that the requester knows that she or he will be charged for the list objects request in V2 style. Bucket
  81. * owners need not specify this parameter in their requests.
  82. *
  83. * @var RequestPayer::*|null
  84. */
  85. private $requestPayer;
  86. /**
  87. * The account ID of the expected bucket owner. If the bucket is owned by a different account, the request fails with
  88. * the HTTP status code `403 Forbidden` (access denied).
  89. *
  90. * @var string|null
  91. */
  92. private $expectedBucketOwner;
  93. /**
  94. * @param array{
  95. * Bucket?: string,
  96. * Delimiter?: string,
  97. * EncodingType?: EncodingType::*,
  98. * MaxKeys?: int,
  99. * Prefix?: string,
  100. * ContinuationToken?: string,
  101. * FetchOwner?: bool,
  102. * StartAfter?: string,
  103. * RequestPayer?: RequestPayer::*,
  104. * ExpectedBucketOwner?: string,
  105. *
  106. * @region?: string,
  107. * } $input
  108. */
  109. public function __construct(array $input = [])
  110. {
  111. $this->bucket = $input['Bucket'] ?? null;
  112. $this->delimiter = $input['Delimiter'] ?? null;
  113. $this->encodingType = $input['EncodingType'] ?? null;
  114. $this->maxKeys = $input['MaxKeys'] ?? null;
  115. $this->prefix = $input['Prefix'] ?? null;
  116. $this->continuationToken = $input['ContinuationToken'] ?? null;
  117. $this->fetchOwner = $input['FetchOwner'] ?? null;
  118. $this->startAfter = $input['StartAfter'] ?? null;
  119. $this->requestPayer = $input['RequestPayer'] ?? null;
  120. $this->expectedBucketOwner = $input['ExpectedBucketOwner'] ?? null;
  121. parent::__construct($input);
  122. }
  123. public static function create($input): self
  124. {
  125. return $input instanceof self ? $input : new self($input);
  126. }
  127. public function getBucket(): ?string
  128. {
  129. return $this->bucket;
  130. }
  131. public function getContinuationToken(): ?string
  132. {
  133. return $this->continuationToken;
  134. }
  135. public function getDelimiter(): ?string
  136. {
  137. return $this->delimiter;
  138. }
  139. /**
  140. * @return EncodingType::*|null
  141. */
  142. public function getEncodingType(): ?string
  143. {
  144. return $this->encodingType;
  145. }
  146. public function getExpectedBucketOwner(): ?string
  147. {
  148. return $this->expectedBucketOwner;
  149. }
  150. public function getFetchOwner(): ?bool
  151. {
  152. return $this->fetchOwner;
  153. }
  154. public function getMaxKeys(): ?int
  155. {
  156. return $this->maxKeys;
  157. }
  158. public function getPrefix(): ?string
  159. {
  160. return $this->prefix;
  161. }
  162. /**
  163. * @return RequestPayer::*|null
  164. */
  165. public function getRequestPayer(): ?string
  166. {
  167. return $this->requestPayer;
  168. }
  169. public function getStartAfter(): ?string
  170. {
  171. return $this->startAfter;
  172. }
  173. /**
  174. * @internal
  175. */
  176. public function request(): Request
  177. {
  178. // Prepare headers
  179. $headers = ['content-type' => 'application/xml'];
  180. if (null !== $this->requestPayer) {
  181. if (!RequestPayer::exists($this->requestPayer)) {
  182. throw new InvalidArgument(sprintf('Invalid parameter "RequestPayer" for "%s". The value "%s" is not a valid "RequestPayer".', __CLASS__, $this->requestPayer));
  183. }
  184. $headers['x-amz-request-payer'] = $this->requestPayer;
  185. }
  186. if (null !== $this->expectedBucketOwner) {
  187. $headers['x-amz-expected-bucket-owner'] = $this->expectedBucketOwner;
  188. }
  189. // Prepare query
  190. $query = [];
  191. if (null !== $this->delimiter) {
  192. $query['delimiter'] = $this->delimiter;
  193. }
  194. if (null !== $this->encodingType) {
  195. if (!EncodingType::exists($this->encodingType)) {
  196. throw new InvalidArgument(sprintf('Invalid parameter "EncodingType" for "%s". The value "%s" is not a valid "EncodingType".', __CLASS__, $this->encodingType));
  197. }
  198. $query['encoding-type'] = $this->encodingType;
  199. }
  200. if (null !== $this->maxKeys) {
  201. $query['max-keys'] = (string) $this->maxKeys;
  202. }
  203. if (null !== $this->prefix) {
  204. $query['prefix'] = $this->prefix;
  205. }
  206. if (null !== $this->continuationToken) {
  207. $query['continuation-token'] = $this->continuationToken;
  208. }
  209. if (null !== $this->fetchOwner) {
  210. $query['fetch-owner'] = $this->fetchOwner ? 'true' : 'false';
  211. }
  212. if (null !== $this->startAfter) {
  213. $query['start-after'] = $this->startAfter;
  214. }
  215. // Prepare URI
  216. $uri = [];
  217. if (null === $v = $this->bucket) {
  218. throw new InvalidArgument(sprintf('Missing parameter "Bucket" for "%s". The value cannot be null.', __CLASS__));
  219. }
  220. $uri['Bucket'] = $v;
  221. $uriString = '/' . rawurlencode($uri['Bucket']) . '?list-type=2';
  222. // Prepare Body
  223. $body = '';
  224. // Return the Request
  225. return new Request('GET', $uriString, $query, $headers, StreamFactory::create($body));
  226. }
  227. public function setBucket(?string $value): self
  228. {
  229. $this->bucket = $value;
  230. return $this;
  231. }
  232. public function setContinuationToken(?string $value): self
  233. {
  234. $this->continuationToken = $value;
  235. return $this;
  236. }
  237. public function setDelimiter(?string $value): self
  238. {
  239. $this->delimiter = $value;
  240. return $this;
  241. }
  242. /**
  243. * @param EncodingType::*|null $value
  244. */
  245. public function setEncodingType(?string $value): self
  246. {
  247. $this->encodingType = $value;
  248. return $this;
  249. }
  250. public function setExpectedBucketOwner(?string $value): self
  251. {
  252. $this->expectedBucketOwner = $value;
  253. return $this;
  254. }
  255. public function setFetchOwner(?bool $value): self
  256. {
  257. $this->fetchOwner = $value;
  258. return $this;
  259. }
  260. public function setMaxKeys(?int $value): self
  261. {
  262. $this->maxKeys = $value;
  263. return $this;
  264. }
  265. public function setPrefix(?string $value): self
  266. {
  267. $this->prefix = $value;
  268. return $this;
  269. }
  270. /**
  271. * @param RequestPayer::*|null $value
  272. */
  273. public function setRequestPayer(?string $value): self
  274. {
  275. $this->requestPayer = $value;
  276. return $this;
  277. }
  278. public function setStartAfter(?string $value): self
  279. {
  280. $this->startAfter = $value;
  281. return $this;
  282. }
  283. }