GetObjectOutput.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. <?php
  2. namespace AsyncAws\S3\Result;
  3. use AsyncAws\Core\Response;
  4. use AsyncAws\Core\Result;
  5. use AsyncAws\Core\Stream\ResultStream;
  6. use AsyncAws\S3\Enum\ObjectLockLegalHoldStatus;
  7. use AsyncAws\S3\Enum\ObjectLockMode;
  8. use AsyncAws\S3\Enum\ReplicationStatus;
  9. use AsyncAws\S3\Enum\RequestCharged;
  10. use AsyncAws\S3\Enum\ServerSideEncryption;
  11. use AsyncAws\S3\Enum\StorageClass;
  12. class GetObjectOutput extends Result
  13. {
  14. /**
  15. * Object data.
  16. */
  17. private $body;
  18. /**
  19. * Specifies whether the object retrieved was (true) or was not (false) a Delete Marker. If false, this response header
  20. * does not appear in the response.
  21. */
  22. private $deleteMarker;
  23. /**
  24. * Indicates that a range of bytes was specified.
  25. */
  26. private $acceptRanges;
  27. /**
  28. * If the object expiration is configured (see PUT Bucket lifecycle), the response includes this header. It includes the
  29. * `expiry-date` and `rule-id` key-value pairs providing object expiration information. The value of the `rule-id` is
  30. * URL-encoded.
  31. */
  32. private $expiration;
  33. /**
  34. * Provides information about object restoration action and expiration time of the restored object copy.
  35. */
  36. private $restore;
  37. /**
  38. * Creation date of the object.
  39. */
  40. private $lastModified;
  41. /**
  42. * Size of the body in bytes.
  43. */
  44. private $contentLength;
  45. /**
  46. * An entity tag (ETag) is an opaque identifier assigned by a web server to a specific version of a resource found at a
  47. * URL.
  48. */
  49. private $etag;
  50. /**
  51. * The base64-encoded, 32-bit CRC32 checksum of the object. This will only be present if it was uploaded with the
  52. * object. With multipart uploads, this may not be a checksum value of the object. For more information about how
  53. * checksums are calculated with multipart uploads, see Checking object integrity [^1] in the *Amazon S3 User Guide*.
  54. *
  55. * [^1]: https://docs.aws.amazon.com/AmazonS3/latest/userguide/checking-object-integrity.html#large-object-checksums
  56. */
  57. private $checksumCrc32;
  58. /**
  59. * The base64-encoded, 32-bit CRC32C checksum of the object. This will only be present if it was uploaded with the
  60. * object. With multipart uploads, this may not be a checksum value of the object. For more information about how
  61. * checksums are calculated with multipart uploads, see Checking object integrity [^1] in the *Amazon S3 User Guide*.
  62. *
  63. * [^1]: https://docs.aws.amazon.com/AmazonS3/latest/userguide/checking-object-integrity.html#large-object-checksums
  64. */
  65. private $checksumCrc32C;
  66. /**
  67. * The base64-encoded, 160-bit SHA-1 digest of the object. This will only be present if it was uploaded with the object.
  68. * With multipart uploads, this may not be a checksum value of the object. For more information about how checksums are
  69. * calculated with multipart uploads, see Checking object integrity [^1] in the *Amazon S3 User Guide*.
  70. *
  71. * [^1]: https://docs.aws.amazon.com/AmazonS3/latest/userguide/checking-object-integrity.html#large-object-checksums
  72. */
  73. private $checksumSha1;
  74. /**
  75. * The base64-encoded, 256-bit SHA-256 digest of the object. This will only be present if it was uploaded with the
  76. * object. With multipart uploads, this may not be a checksum value of the object. For more information about how
  77. * checksums are calculated with multipart uploads, see Checking object integrity [^1] in the *Amazon S3 User Guide*.
  78. *
  79. * [^1]: https://docs.aws.amazon.com/AmazonS3/latest/userguide/checking-object-integrity.html#large-object-checksums
  80. */
  81. private $checksumSha256;
  82. /**
  83. * This is set to the number of metadata entries not returned in `x-amz-meta` headers. This can happen if you create
  84. * metadata using an API like SOAP that supports more flexible metadata than the REST API. For example, using SOAP, you
  85. * can create metadata whose values are not legal HTTP headers.
  86. */
  87. private $missingMeta;
  88. /**
  89. * Version of the object.
  90. */
  91. private $versionId;
  92. /**
  93. * Specifies caching behavior along the request/reply chain.
  94. */
  95. private $cacheControl;
  96. /**
  97. * Specifies presentational information for the object.
  98. */
  99. private $contentDisposition;
  100. /**
  101. * Specifies what content encodings have been applied to the object and thus what decoding mechanisms must be applied to
  102. * obtain the media-type referenced by the Content-Type header field.
  103. */
  104. private $contentEncoding;
  105. /**
  106. * The language the content is in.
  107. */
  108. private $contentLanguage;
  109. /**
  110. * The portion of the object returned in the response.
  111. */
  112. private $contentRange;
  113. /**
  114. * A standard MIME type describing the format of the object data.
  115. */
  116. private $contentType;
  117. /**
  118. * The date and time at which the object is no longer cacheable.
  119. */
  120. private $expires;
  121. /**
  122. * If the bucket is configured as a website, redirects requests for this object to another object in the same bucket or
  123. * to an external URL. Amazon S3 stores the value of this header in the object metadata.
  124. */
  125. private $websiteRedirectLocation;
  126. /**
  127. * The server-side encryption algorithm used when storing this object in Amazon S3 (for example, `AES256`, `aws:kms`,
  128. * `aws:kms:dsse`).
  129. */
  130. private $serverSideEncryption;
  131. /**
  132. * A map of metadata to store with the object in S3.
  133. */
  134. private $metadata;
  135. /**
  136. * If server-side encryption with a customer-provided encryption key was requested, the response will include this
  137. * header confirming the encryption algorithm used.
  138. */
  139. private $sseCustomerAlgorithm;
  140. /**
  141. * If server-side encryption with a customer-provided encryption key was requested, the response will include this
  142. * header to provide round-trip message integrity verification of the customer-provided encryption key.
  143. */
  144. private $sseCustomerKeyMd5;
  145. /**
  146. * If present, specifies the ID of the Key Management Service (KMS) symmetric encryption customer managed key that was
  147. * used for the object.
  148. */
  149. private $sseKmsKeyId;
  150. /**
  151. * Indicates whether the object uses an S3 Bucket Key for server-side encryption with Key Management Service (KMS) keys
  152. * (SSE-KMS).
  153. */
  154. private $bucketKeyEnabled;
  155. /**
  156. * Provides storage class information of the object. Amazon S3 returns this header for all objects except for S3
  157. * Standard storage class objects.
  158. */
  159. private $storageClass;
  160. private $requestCharged;
  161. /**
  162. * Amazon S3 can return this if your request involves a bucket that is either a source or destination in a replication
  163. * rule.
  164. */
  165. private $replicationStatus;
  166. /**
  167. * The count of parts this object has. This value is only returned if you specify `partNumber` in your request and the
  168. * object was uploaded as a multipart upload.
  169. */
  170. private $partsCount;
  171. /**
  172. * The number of tags, if any, on the object.
  173. */
  174. private $tagCount;
  175. /**
  176. * The Object Lock mode currently in place for this object.
  177. */
  178. private $objectLockMode;
  179. /**
  180. * The date and time when this object's Object Lock will expire.
  181. */
  182. private $objectLockRetainUntilDate;
  183. /**
  184. * Indicates whether this object has an active legal hold. This field is only returned if you have permission to view an
  185. * object's legal hold status.
  186. */
  187. private $objectLockLegalHoldStatus;
  188. public function getAcceptRanges(): ?string
  189. {
  190. $this->initialize();
  191. return $this->acceptRanges;
  192. }
  193. public function getBody(): ResultStream
  194. {
  195. $this->initialize();
  196. return $this->body;
  197. }
  198. public function getBucketKeyEnabled(): ?bool
  199. {
  200. $this->initialize();
  201. return $this->bucketKeyEnabled;
  202. }
  203. public function getCacheControl(): ?string
  204. {
  205. $this->initialize();
  206. return $this->cacheControl;
  207. }
  208. public function getChecksumCrc32(): ?string
  209. {
  210. $this->initialize();
  211. return $this->checksumCrc32;
  212. }
  213. public function getChecksumCrc32C(): ?string
  214. {
  215. $this->initialize();
  216. return $this->checksumCrc32C;
  217. }
  218. public function getChecksumSha1(): ?string
  219. {
  220. $this->initialize();
  221. return $this->checksumSha1;
  222. }
  223. public function getChecksumSha256(): ?string
  224. {
  225. $this->initialize();
  226. return $this->checksumSha256;
  227. }
  228. public function getContentDisposition(): ?string
  229. {
  230. $this->initialize();
  231. return $this->contentDisposition;
  232. }
  233. public function getContentEncoding(): ?string
  234. {
  235. $this->initialize();
  236. return $this->contentEncoding;
  237. }
  238. public function getContentLanguage(): ?string
  239. {
  240. $this->initialize();
  241. return $this->contentLanguage;
  242. }
  243. public function getContentLength(): ?string
  244. {
  245. $this->initialize();
  246. return $this->contentLength;
  247. }
  248. public function getContentRange(): ?string
  249. {
  250. $this->initialize();
  251. return $this->contentRange;
  252. }
  253. public function getContentType(): ?string
  254. {
  255. $this->initialize();
  256. return $this->contentType;
  257. }
  258. public function getDeleteMarker(): ?bool
  259. {
  260. $this->initialize();
  261. return $this->deleteMarker;
  262. }
  263. public function getEtag(): ?string
  264. {
  265. $this->initialize();
  266. return $this->etag;
  267. }
  268. public function getExpiration(): ?string
  269. {
  270. $this->initialize();
  271. return $this->expiration;
  272. }
  273. public function getExpires(): ?\DateTimeImmutable
  274. {
  275. $this->initialize();
  276. return $this->expires;
  277. }
  278. public function getLastModified(): ?\DateTimeImmutable
  279. {
  280. $this->initialize();
  281. return $this->lastModified;
  282. }
  283. /**
  284. * @return array<string, string>
  285. */
  286. public function getMetadata(): array
  287. {
  288. $this->initialize();
  289. return $this->metadata;
  290. }
  291. public function getMissingMeta(): ?int
  292. {
  293. $this->initialize();
  294. return $this->missingMeta;
  295. }
  296. /**
  297. * @return ObjectLockLegalHoldStatus::*|null
  298. */
  299. public function getObjectLockLegalHoldStatus(): ?string
  300. {
  301. $this->initialize();
  302. return $this->objectLockLegalHoldStatus;
  303. }
  304. /**
  305. * @return ObjectLockMode::*|null
  306. */
  307. public function getObjectLockMode(): ?string
  308. {
  309. $this->initialize();
  310. return $this->objectLockMode;
  311. }
  312. public function getObjectLockRetainUntilDate(): ?\DateTimeImmutable
  313. {
  314. $this->initialize();
  315. return $this->objectLockRetainUntilDate;
  316. }
  317. public function getPartsCount(): ?int
  318. {
  319. $this->initialize();
  320. return $this->partsCount;
  321. }
  322. /**
  323. * @return ReplicationStatus::*|null
  324. */
  325. public function getReplicationStatus(): ?string
  326. {
  327. $this->initialize();
  328. return $this->replicationStatus;
  329. }
  330. /**
  331. * @return RequestCharged::*|null
  332. */
  333. public function getRequestCharged(): ?string
  334. {
  335. $this->initialize();
  336. return $this->requestCharged;
  337. }
  338. public function getRestore(): ?string
  339. {
  340. $this->initialize();
  341. return $this->restore;
  342. }
  343. /**
  344. * @return ServerSideEncryption::*|null
  345. */
  346. public function getServerSideEncryption(): ?string
  347. {
  348. $this->initialize();
  349. return $this->serverSideEncryption;
  350. }
  351. public function getSseCustomerAlgorithm(): ?string
  352. {
  353. $this->initialize();
  354. return $this->sseCustomerAlgorithm;
  355. }
  356. public function getSseCustomerKeyMd5(): ?string
  357. {
  358. $this->initialize();
  359. return $this->sseCustomerKeyMd5;
  360. }
  361. public function getSseKmsKeyId(): ?string
  362. {
  363. $this->initialize();
  364. return $this->sseKmsKeyId;
  365. }
  366. /**
  367. * @return StorageClass::*|null
  368. */
  369. public function getStorageClass(): ?string
  370. {
  371. $this->initialize();
  372. return $this->storageClass;
  373. }
  374. public function getTagCount(): ?int
  375. {
  376. $this->initialize();
  377. return $this->tagCount;
  378. }
  379. public function getVersionId(): ?string
  380. {
  381. $this->initialize();
  382. return $this->versionId;
  383. }
  384. public function getWebsiteRedirectLocation(): ?string
  385. {
  386. $this->initialize();
  387. return $this->websiteRedirectLocation;
  388. }
  389. protected function populateResult(Response $response): void
  390. {
  391. $headers = $response->getHeaders();
  392. $this->deleteMarker = isset($headers['x-amz-delete-marker'][0]) ? filter_var($headers['x-amz-delete-marker'][0], \FILTER_VALIDATE_BOOLEAN) : null;
  393. $this->acceptRanges = $headers['accept-ranges'][0] ?? null;
  394. $this->expiration = $headers['x-amz-expiration'][0] ?? null;
  395. $this->restore = $headers['x-amz-restore'][0] ?? null;
  396. $this->lastModified = isset($headers['last-modified'][0]) ? new \DateTimeImmutable($headers['last-modified'][0]) : null;
  397. $this->contentLength = $headers['content-length'][0] ?? null;
  398. $this->etag = $headers['etag'][0] ?? null;
  399. $this->checksumCrc32 = $headers['x-amz-checksum-crc32'][0] ?? null;
  400. $this->checksumCrc32C = $headers['x-amz-checksum-crc32c'][0] ?? null;
  401. $this->checksumSha1 = $headers['x-amz-checksum-sha1'][0] ?? null;
  402. $this->checksumSha256 = $headers['x-amz-checksum-sha256'][0] ?? null;
  403. $this->missingMeta = isset($headers['x-amz-missing-meta'][0]) ? filter_var($headers['x-amz-missing-meta'][0], \FILTER_VALIDATE_INT) : null;
  404. $this->versionId = $headers['x-amz-version-id'][0] ?? null;
  405. $this->cacheControl = $headers['cache-control'][0] ?? null;
  406. $this->contentDisposition = $headers['content-disposition'][0] ?? null;
  407. $this->contentEncoding = $headers['content-encoding'][0] ?? null;
  408. $this->contentLanguage = $headers['content-language'][0] ?? null;
  409. $this->contentRange = $headers['content-range'][0] ?? null;
  410. $this->contentType = $headers['content-type'][0] ?? null;
  411. $this->expires = isset($headers['expires'][0]) ? new \DateTimeImmutable($headers['expires'][0]) : null;
  412. $this->websiteRedirectLocation = $headers['x-amz-website-redirect-location'][0] ?? null;
  413. $this->serverSideEncryption = $headers['x-amz-server-side-encryption'][0] ?? null;
  414. $this->sseCustomerAlgorithm = $headers['x-amz-server-side-encryption-customer-algorithm'][0] ?? null;
  415. $this->sseCustomerKeyMd5 = $headers['x-amz-server-side-encryption-customer-key-md5'][0] ?? null;
  416. $this->sseKmsKeyId = $headers['x-amz-server-side-encryption-aws-kms-key-id'][0] ?? null;
  417. $this->bucketKeyEnabled = isset($headers['x-amz-server-side-encryption-bucket-key-enabled'][0]) ? filter_var($headers['x-amz-server-side-encryption-bucket-key-enabled'][0], \FILTER_VALIDATE_BOOLEAN) : null;
  418. $this->storageClass = $headers['x-amz-storage-class'][0] ?? null;
  419. $this->requestCharged = $headers['x-amz-request-charged'][0] ?? null;
  420. $this->replicationStatus = $headers['x-amz-replication-status'][0] ?? null;
  421. $this->partsCount = isset($headers['x-amz-mp-parts-count'][0]) ? filter_var($headers['x-amz-mp-parts-count'][0], \FILTER_VALIDATE_INT) : null;
  422. $this->tagCount = isset($headers['x-amz-tagging-count'][0]) ? filter_var($headers['x-amz-tagging-count'][0], \FILTER_VALIDATE_INT) : null;
  423. $this->objectLockMode = $headers['x-amz-object-lock-mode'][0] ?? null;
  424. $this->objectLockRetainUntilDate = isset($headers['x-amz-object-lock-retain-until-date'][0]) ? new \DateTimeImmutable($headers['x-amz-object-lock-retain-until-date'][0]) : null;
  425. $this->objectLockLegalHoldStatus = $headers['x-amz-object-lock-legal-hold'][0] ?? null;
  426. $this->metadata = [];
  427. foreach ($headers as $name => $value) {
  428. if ('x-amz-meta-' === substr($name, 0, 11)) {
  429. $this->metadata[substr($name, 11)] = $value[0];
  430. }
  431. }
  432. $this->body = $response->toStream();
  433. }
  434. }