GetObjectRequest.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  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\ChecksumMode;
  8. use AsyncAws\S3\Enum\RequestPayer;
  9. final class GetObjectRequest extends Input
  10. {
  11. /**
  12. * The bucket name containing the object.
  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 using an Object Lambda access point the hostname takes the form
  20. * *AccessPointName*-*AccountId*.s3-object-lambda.*Region*.amazonaws.com.
  21. *
  22. * When you use this action with Amazon S3 on Outposts, you must direct requests to the S3 on Outposts hostname. The S3
  23. * on Outposts hostname takes the form `*AccessPointName*-*AccountId*.*outpostID*.s3-outposts.*Region*.amazonaws.com`.
  24. * When you use this action with S3 on Outposts through the Amazon Web Services SDKs, you provide the Outposts access
  25. * point ARN in place of the bucket name. For more information about S3 on Outposts ARNs, see What is S3 on Outposts
  26. * [^2] in the *Amazon S3 User Guide*.
  27. *
  28. * [^1]: https://docs.aws.amazon.com/AmazonS3/latest/userguide/using-access-points.html
  29. * [^2]: https://docs.aws.amazon.com/AmazonS3/latest/userguide/S3onOutposts.html
  30. *
  31. * @required
  32. *
  33. * @var string|null
  34. */
  35. private $bucket;
  36. /**
  37. * Return the object only if its entity tag (ETag) is the same as the one specified; otherwise, return a 412
  38. * (precondition failed) error.
  39. *
  40. * @var string|null
  41. */
  42. private $ifMatch;
  43. /**
  44. * Return the object only if it has been modified since the specified time; otherwise, return a 304 (not modified)
  45. * error.
  46. *
  47. * @var \DateTimeImmutable|null
  48. */
  49. private $ifModifiedSince;
  50. /**
  51. * Return the object only if its entity tag (ETag) is different from the one specified; otherwise, return a 304 (not
  52. * modified) error.
  53. *
  54. * @var string|null
  55. */
  56. private $ifNoneMatch;
  57. /**
  58. * Return the object only if it has not been modified since the specified time; otherwise, return a 412 (precondition
  59. * failed) error.
  60. *
  61. * @var \DateTimeImmutable|null
  62. */
  63. private $ifUnmodifiedSince;
  64. /**
  65. * Key of the object to get.
  66. *
  67. * @required
  68. *
  69. * @var string|null
  70. */
  71. private $key;
  72. /**
  73. * Downloads the specified range bytes of an object. For more information about the HTTP Range header, see
  74. * https://www.rfc-editor.org/rfc/rfc9110.html#name-range [^1].
  75. *
  76. * > Amazon S3 doesn't support retrieving multiple ranges of data per `GET` request.
  77. *
  78. * [^1]: https://www.rfc-editor.org/rfc/rfc9110.html#name-range
  79. *
  80. * @var string|null
  81. */
  82. private $range;
  83. /**
  84. * Sets the `Cache-Control` header of the response.
  85. *
  86. * @var string|null
  87. */
  88. private $responseCacheControl;
  89. /**
  90. * Sets the `Content-Disposition` header of the response.
  91. *
  92. * @var string|null
  93. */
  94. private $responseContentDisposition;
  95. /**
  96. * Sets the `Content-Encoding` header of the response.
  97. *
  98. * @var string|null
  99. */
  100. private $responseContentEncoding;
  101. /**
  102. * Sets the `Content-Language` header of the response.
  103. *
  104. * @var string|null
  105. */
  106. private $responseContentLanguage;
  107. /**
  108. * Sets the `Content-Type` header of the response.
  109. *
  110. * @var string|null
  111. */
  112. private $responseContentType;
  113. /**
  114. * Sets the `Expires` header of the response.
  115. *
  116. * @var \DateTimeImmutable|null
  117. */
  118. private $responseExpires;
  119. /**
  120. * VersionId used to reference a specific version of the object.
  121. *
  122. * @var string|null
  123. */
  124. private $versionId;
  125. /**
  126. * Specifies the algorithm to use to when decrypting the object (for example, AES256).
  127. *
  128. * @var string|null
  129. */
  130. private $sseCustomerAlgorithm;
  131. /**
  132. * Specifies the customer-provided encryption key for Amazon S3 used to encrypt the data. This value is used to decrypt
  133. * the object when recovering it and must match the one used when storing the data. The key must be appropriate for use
  134. * with the algorithm specified in the `x-amz-server-side-encryption-customer-algorithm` header.
  135. *
  136. * @var string|null
  137. */
  138. private $sseCustomerKey;
  139. /**
  140. * Specifies the 128-bit MD5 digest of the encryption key according to RFC 1321. Amazon S3 uses this header for a
  141. * message integrity check to ensure that the encryption key was transmitted without error.
  142. *
  143. * @var string|null
  144. */
  145. private $sseCustomerKeyMd5;
  146. /**
  147. * @var RequestPayer::*|null
  148. */
  149. private $requestPayer;
  150. /**
  151. * Part number of the object being read. This is a positive integer between 1 and 10,000. Effectively performs a
  152. * 'ranged' GET request for the part specified. Useful for downloading just a part of an object.
  153. *
  154. * @var int|null
  155. */
  156. private $partNumber;
  157. /**
  158. * The account ID of the expected bucket owner. If the bucket is owned by a different account, the request fails with
  159. * the HTTP status code `403 Forbidden` (access denied).
  160. *
  161. * @var string|null
  162. */
  163. private $expectedBucketOwner;
  164. /**
  165. * To retrieve the checksum, this mode must be enabled.
  166. *
  167. * @var ChecksumMode::*|null
  168. */
  169. private $checksumMode;
  170. /**
  171. * @param array{
  172. * Bucket?: string,
  173. * IfMatch?: string,
  174. * IfModifiedSince?: \DateTimeImmutable|string,
  175. * IfNoneMatch?: string,
  176. * IfUnmodifiedSince?: \DateTimeImmutable|string,
  177. * Key?: string,
  178. * Range?: string,
  179. * ResponseCacheControl?: string,
  180. * ResponseContentDisposition?: string,
  181. * ResponseContentEncoding?: string,
  182. * ResponseContentLanguage?: string,
  183. * ResponseContentType?: string,
  184. * ResponseExpires?: \DateTimeImmutable|string,
  185. * VersionId?: string,
  186. * SSECustomerAlgorithm?: string,
  187. * SSECustomerKey?: string,
  188. * SSECustomerKeyMD5?: string,
  189. * RequestPayer?: RequestPayer::*,
  190. * PartNumber?: int,
  191. * ExpectedBucketOwner?: string,
  192. * ChecksumMode?: ChecksumMode::*,
  193. *
  194. * @region?: string,
  195. * } $input
  196. */
  197. public function __construct(array $input = [])
  198. {
  199. $this->bucket = $input['Bucket'] ?? null;
  200. $this->ifMatch = $input['IfMatch'] ?? null;
  201. $this->ifModifiedSince = !isset($input['IfModifiedSince']) ? null : ($input['IfModifiedSince'] instanceof \DateTimeImmutable ? $input['IfModifiedSince'] : new \DateTimeImmutable($input['IfModifiedSince']));
  202. $this->ifNoneMatch = $input['IfNoneMatch'] ?? null;
  203. $this->ifUnmodifiedSince = !isset($input['IfUnmodifiedSince']) ? null : ($input['IfUnmodifiedSince'] instanceof \DateTimeImmutable ? $input['IfUnmodifiedSince'] : new \DateTimeImmutable($input['IfUnmodifiedSince']));
  204. $this->key = $input['Key'] ?? null;
  205. $this->range = $input['Range'] ?? null;
  206. $this->responseCacheControl = $input['ResponseCacheControl'] ?? null;
  207. $this->responseContentDisposition = $input['ResponseContentDisposition'] ?? null;
  208. $this->responseContentEncoding = $input['ResponseContentEncoding'] ?? null;
  209. $this->responseContentLanguage = $input['ResponseContentLanguage'] ?? null;
  210. $this->responseContentType = $input['ResponseContentType'] ?? null;
  211. $this->responseExpires = !isset($input['ResponseExpires']) ? null : ($input['ResponseExpires'] instanceof \DateTimeImmutable ? $input['ResponseExpires'] : new \DateTimeImmutable($input['ResponseExpires']));
  212. $this->versionId = $input['VersionId'] ?? null;
  213. $this->sseCustomerAlgorithm = $input['SSECustomerAlgorithm'] ?? null;
  214. $this->sseCustomerKey = $input['SSECustomerKey'] ?? null;
  215. $this->sseCustomerKeyMd5 = $input['SSECustomerKeyMD5'] ?? null;
  216. $this->requestPayer = $input['RequestPayer'] ?? null;
  217. $this->partNumber = $input['PartNumber'] ?? null;
  218. $this->expectedBucketOwner = $input['ExpectedBucketOwner'] ?? null;
  219. $this->checksumMode = $input['ChecksumMode'] ?? null;
  220. parent::__construct($input);
  221. }
  222. public static function create($input): self
  223. {
  224. return $input instanceof self ? $input : new self($input);
  225. }
  226. public function getBucket(): ?string
  227. {
  228. return $this->bucket;
  229. }
  230. /**
  231. * @return ChecksumMode::*|null
  232. */
  233. public function getChecksumMode(): ?string
  234. {
  235. return $this->checksumMode;
  236. }
  237. public function getExpectedBucketOwner(): ?string
  238. {
  239. return $this->expectedBucketOwner;
  240. }
  241. public function getIfMatch(): ?string
  242. {
  243. return $this->ifMatch;
  244. }
  245. public function getIfModifiedSince(): ?\DateTimeImmutable
  246. {
  247. return $this->ifModifiedSince;
  248. }
  249. public function getIfNoneMatch(): ?string
  250. {
  251. return $this->ifNoneMatch;
  252. }
  253. public function getIfUnmodifiedSince(): ?\DateTimeImmutable
  254. {
  255. return $this->ifUnmodifiedSince;
  256. }
  257. public function getKey(): ?string
  258. {
  259. return $this->key;
  260. }
  261. public function getPartNumber(): ?int
  262. {
  263. return $this->partNumber;
  264. }
  265. public function getRange(): ?string
  266. {
  267. return $this->range;
  268. }
  269. /**
  270. * @return RequestPayer::*|null
  271. */
  272. public function getRequestPayer(): ?string
  273. {
  274. return $this->requestPayer;
  275. }
  276. public function getResponseCacheControl(): ?string
  277. {
  278. return $this->responseCacheControl;
  279. }
  280. public function getResponseContentDisposition(): ?string
  281. {
  282. return $this->responseContentDisposition;
  283. }
  284. public function getResponseContentEncoding(): ?string
  285. {
  286. return $this->responseContentEncoding;
  287. }
  288. public function getResponseContentLanguage(): ?string
  289. {
  290. return $this->responseContentLanguage;
  291. }
  292. public function getResponseContentType(): ?string
  293. {
  294. return $this->responseContentType;
  295. }
  296. public function getResponseExpires(): ?\DateTimeImmutable
  297. {
  298. return $this->responseExpires;
  299. }
  300. public function getSseCustomerAlgorithm(): ?string
  301. {
  302. return $this->sseCustomerAlgorithm;
  303. }
  304. public function getSseCustomerKey(): ?string
  305. {
  306. return $this->sseCustomerKey;
  307. }
  308. public function getSseCustomerKeyMd5(): ?string
  309. {
  310. return $this->sseCustomerKeyMd5;
  311. }
  312. public function getVersionId(): ?string
  313. {
  314. return $this->versionId;
  315. }
  316. /**
  317. * @internal
  318. */
  319. public function request(): Request
  320. {
  321. // Prepare headers
  322. $headers = ['content-type' => 'application/xml'];
  323. if (null !== $this->ifMatch) {
  324. $headers['If-Match'] = $this->ifMatch;
  325. }
  326. if (null !== $this->ifModifiedSince) {
  327. $headers['If-Modified-Since'] = $this->ifModifiedSince->setTimezone(new \DateTimeZone('GMT'))->format(\DateTimeInterface::RFC7231);
  328. }
  329. if (null !== $this->ifNoneMatch) {
  330. $headers['If-None-Match'] = $this->ifNoneMatch;
  331. }
  332. if (null !== $this->ifUnmodifiedSince) {
  333. $headers['If-Unmodified-Since'] = $this->ifUnmodifiedSince->setTimezone(new \DateTimeZone('GMT'))->format(\DateTimeInterface::RFC7231);
  334. }
  335. if (null !== $this->range) {
  336. $headers['Range'] = $this->range;
  337. }
  338. if (null !== $this->sseCustomerAlgorithm) {
  339. $headers['x-amz-server-side-encryption-customer-algorithm'] = $this->sseCustomerAlgorithm;
  340. }
  341. if (null !== $this->sseCustomerKey) {
  342. $headers['x-amz-server-side-encryption-customer-key'] = $this->sseCustomerKey;
  343. }
  344. if (null !== $this->sseCustomerKeyMd5) {
  345. $headers['x-amz-server-side-encryption-customer-key-MD5'] = $this->sseCustomerKeyMd5;
  346. }
  347. if (null !== $this->requestPayer) {
  348. if (!RequestPayer::exists($this->requestPayer)) {
  349. throw new InvalidArgument(sprintf('Invalid parameter "RequestPayer" for "%s". The value "%s" is not a valid "RequestPayer".', __CLASS__, $this->requestPayer));
  350. }
  351. $headers['x-amz-request-payer'] = $this->requestPayer;
  352. }
  353. if (null !== $this->expectedBucketOwner) {
  354. $headers['x-amz-expected-bucket-owner'] = $this->expectedBucketOwner;
  355. }
  356. if (null !== $this->checksumMode) {
  357. if (!ChecksumMode::exists($this->checksumMode)) {
  358. throw new InvalidArgument(sprintf('Invalid parameter "ChecksumMode" for "%s". The value "%s" is not a valid "ChecksumMode".', __CLASS__, $this->checksumMode));
  359. }
  360. $headers['x-amz-checksum-mode'] = $this->checksumMode;
  361. }
  362. // Prepare query
  363. $query = [];
  364. if (null !== $this->responseCacheControl) {
  365. $query['response-cache-control'] = $this->responseCacheControl;
  366. }
  367. if (null !== $this->responseContentDisposition) {
  368. $query['response-content-disposition'] = $this->responseContentDisposition;
  369. }
  370. if (null !== $this->responseContentEncoding) {
  371. $query['response-content-encoding'] = $this->responseContentEncoding;
  372. }
  373. if (null !== $this->responseContentLanguage) {
  374. $query['response-content-language'] = $this->responseContentLanguage;
  375. }
  376. if (null !== $this->responseContentType) {
  377. $query['response-content-type'] = $this->responseContentType;
  378. }
  379. if (null !== $this->responseExpires) {
  380. $query['response-expires'] = $this->responseExpires->setTimezone(new \DateTimeZone('GMT'))->format(\DateTimeInterface::RFC7231);
  381. }
  382. if (null !== $this->versionId) {
  383. $query['versionId'] = $this->versionId;
  384. }
  385. if (null !== $this->partNumber) {
  386. $query['partNumber'] = (string) $this->partNumber;
  387. }
  388. // Prepare URI
  389. $uri = [];
  390. if (null === $v = $this->bucket) {
  391. throw new InvalidArgument(sprintf('Missing parameter "Bucket" for "%s". The value cannot be null.', __CLASS__));
  392. }
  393. $uri['Bucket'] = $v;
  394. if (null === $v = $this->key) {
  395. throw new InvalidArgument(sprintf('Missing parameter "Key" for "%s". The value cannot be null.', __CLASS__));
  396. }
  397. $uri['Key'] = $v;
  398. $uriString = '/' . rawurlencode($uri['Bucket']) . '/' . str_replace('%2F', '/', rawurlencode($uri['Key']));
  399. // Prepare Body
  400. $body = '';
  401. // Return the Request
  402. return new Request('GET', $uriString, $query, $headers, StreamFactory::create($body));
  403. }
  404. public function setBucket(?string $value): self
  405. {
  406. $this->bucket = $value;
  407. return $this;
  408. }
  409. /**
  410. * @param ChecksumMode::*|null $value
  411. */
  412. public function setChecksumMode(?string $value): self
  413. {
  414. $this->checksumMode = $value;
  415. return $this;
  416. }
  417. public function setExpectedBucketOwner(?string $value): self
  418. {
  419. $this->expectedBucketOwner = $value;
  420. return $this;
  421. }
  422. public function setIfMatch(?string $value): self
  423. {
  424. $this->ifMatch = $value;
  425. return $this;
  426. }
  427. public function setIfModifiedSince(?\DateTimeImmutable $value): self
  428. {
  429. $this->ifModifiedSince = $value;
  430. return $this;
  431. }
  432. public function setIfNoneMatch(?string $value): self
  433. {
  434. $this->ifNoneMatch = $value;
  435. return $this;
  436. }
  437. public function setIfUnmodifiedSince(?\DateTimeImmutable $value): self
  438. {
  439. $this->ifUnmodifiedSince = $value;
  440. return $this;
  441. }
  442. public function setKey(?string $value): self
  443. {
  444. $this->key = $value;
  445. return $this;
  446. }
  447. public function setPartNumber(?int $value): self
  448. {
  449. $this->partNumber = $value;
  450. return $this;
  451. }
  452. public function setRange(?string $value): self
  453. {
  454. $this->range = $value;
  455. return $this;
  456. }
  457. /**
  458. * @param RequestPayer::*|null $value
  459. */
  460. public function setRequestPayer(?string $value): self
  461. {
  462. $this->requestPayer = $value;
  463. return $this;
  464. }
  465. public function setResponseCacheControl(?string $value): self
  466. {
  467. $this->responseCacheControl = $value;
  468. return $this;
  469. }
  470. public function setResponseContentDisposition(?string $value): self
  471. {
  472. $this->responseContentDisposition = $value;
  473. return $this;
  474. }
  475. public function setResponseContentEncoding(?string $value): self
  476. {
  477. $this->responseContentEncoding = $value;
  478. return $this;
  479. }
  480. public function setResponseContentLanguage(?string $value): self
  481. {
  482. $this->responseContentLanguage = $value;
  483. return $this;
  484. }
  485. public function setResponseContentType(?string $value): self
  486. {
  487. $this->responseContentType = $value;
  488. return $this;
  489. }
  490. public function setResponseExpires(?\DateTimeImmutable $value): self
  491. {
  492. $this->responseExpires = $value;
  493. return $this;
  494. }
  495. public function setSseCustomerAlgorithm(?string $value): self
  496. {
  497. $this->sseCustomerAlgorithm = $value;
  498. return $this;
  499. }
  500. public function setSseCustomerKey(?string $value): self
  501. {
  502. $this->sseCustomerKey = $value;
  503. return $this;
  504. }
  505. public function setSseCustomerKeyMd5(?string $value): self
  506. {
  507. $this->sseCustomerKeyMd5 = $value;
  508. return $this;
  509. }
  510. public function setVersionId(?string $value): self
  511. {
  512. $this->versionId = $value;
  513. return $this;
  514. }
  515. }