GetObjectAclOutput.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. namespace AsyncAws\S3\Result;
  3. use AsyncAws\Core\Response;
  4. use AsyncAws\Core\Result;
  5. use AsyncAws\S3\Enum\RequestCharged;
  6. use AsyncAws\S3\ValueObject\Grant;
  7. use AsyncAws\S3\ValueObject\Grantee;
  8. use AsyncAws\S3\ValueObject\Owner;
  9. class GetObjectAclOutput extends Result
  10. {
  11. /**
  12. * Container for the bucket owner's display name and ID.
  13. */
  14. private $owner;
  15. /**
  16. * A list of grants.
  17. */
  18. private $grants;
  19. private $requestCharged;
  20. /**
  21. * @return Grant[]
  22. */
  23. public function getGrants(): array
  24. {
  25. $this->initialize();
  26. return $this->grants;
  27. }
  28. public function getOwner(): ?Owner
  29. {
  30. $this->initialize();
  31. return $this->owner;
  32. }
  33. /**
  34. * @return RequestCharged::*|null
  35. */
  36. public function getRequestCharged(): ?string
  37. {
  38. $this->initialize();
  39. return $this->requestCharged;
  40. }
  41. protected function populateResult(Response $response): void
  42. {
  43. $headers = $response->getHeaders();
  44. $this->requestCharged = $headers['x-amz-request-charged'][0] ?? null;
  45. $data = new \SimpleXMLElement($response->getContent());
  46. $this->owner = !$data->Owner ? null : new Owner([
  47. 'DisplayName' => ($v = $data->Owner->DisplayName) ? (string) $v : null,
  48. 'ID' => ($v = $data->Owner->ID) ? (string) $v : null,
  49. ]);
  50. $this->grants = !$data->AccessControlList ? [] : $this->populateResultGrants($data->AccessControlList);
  51. }
  52. /**
  53. * @return Grant[]
  54. */
  55. private function populateResultGrants(\SimpleXMLElement $xml): array
  56. {
  57. $items = [];
  58. foreach ($xml->Grant as $item) {
  59. $items[] = new Grant([
  60. 'Grantee' => !$item->Grantee ? null : new Grantee([
  61. 'DisplayName' => ($v = $item->Grantee->DisplayName) ? (string) $v : null,
  62. 'EmailAddress' => ($v = $item->Grantee->EmailAddress) ? (string) $v : null,
  63. 'ID' => ($v = $item->Grantee->ID) ? (string) $v : null,
  64. 'Type' => (string) ($item->Grantee->attributes('xsi', true)['type'][0] ?? null),
  65. 'URI' => ($v = $item->Grantee->URI) ? (string) $v : null,
  66. ]),
  67. 'Permission' => ($v = $item->Permission) ? (string) $v : null,
  68. ]);
  69. }
  70. return $items;
  71. }
  72. }