Grantee.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. namespace AsyncAws\S3\ValueObject;
  3. use AsyncAws\Core\Exception\InvalidArgument;
  4. use AsyncAws\S3\Enum\Type;
  5. /**
  6. * Container for the person being granted permissions.
  7. */
  8. final class Grantee
  9. {
  10. /**
  11. * Screen name of the grantee.
  12. */
  13. private $displayName;
  14. /**
  15. * Email address of the grantee.
  16. *
  17. * > Using email addresses to specify a grantee is only supported in the following Amazon Web Services Regions:
  18. * >
  19. * > - US East (N. Virginia)
  20. * > - US West (N. California)
  21. * > - US West (Oregon)
  22. * > - Asia Pacific (Singapore)
  23. * > - Asia Pacific (Sydney)
  24. * > - Asia Pacific (Tokyo)
  25. * > - Europe (Ireland)
  26. * > - South America (São Paulo)
  27. * >
  28. * > For a list of all the Amazon S3 supported Regions and endpoints, see Regions and Endpoints [^1] in the Amazon Web
  29. * > Services General Reference.
  30. *
  31. * [^1]: https://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region
  32. */
  33. private $emailAddress;
  34. /**
  35. * The canonical user ID of the grantee.
  36. */
  37. private $id;
  38. /**
  39. * Type of grantee.
  40. */
  41. private $type;
  42. /**
  43. * URI of the grantee group.
  44. */
  45. private $uri;
  46. /**
  47. * @param array{
  48. * DisplayName?: null|string,
  49. * EmailAddress?: null|string,
  50. * ID?: null|string,
  51. * Type: Type::*,
  52. * URI?: null|string,
  53. * } $input
  54. */
  55. public function __construct(array $input)
  56. {
  57. $this->displayName = $input['DisplayName'] ?? null;
  58. $this->emailAddress = $input['EmailAddress'] ?? null;
  59. $this->id = $input['ID'] ?? null;
  60. $this->type = $input['Type'] ?? null;
  61. $this->uri = $input['URI'] ?? null;
  62. }
  63. public static function create($input): self
  64. {
  65. return $input instanceof self ? $input : new self($input);
  66. }
  67. public function getDisplayName(): ?string
  68. {
  69. return $this->displayName;
  70. }
  71. public function getEmailAddress(): ?string
  72. {
  73. return $this->emailAddress;
  74. }
  75. public function getId(): ?string
  76. {
  77. return $this->id;
  78. }
  79. /**
  80. * @return Type::*
  81. */
  82. public function getType(): string
  83. {
  84. return $this->type;
  85. }
  86. public function getUri(): ?string
  87. {
  88. return $this->uri;
  89. }
  90. /**
  91. * @internal
  92. */
  93. public function requestBody(\DOMElement $node, \DOMDocument $document): void
  94. {
  95. if (null !== $v = $this->displayName) {
  96. $node->appendChild($document->createElement('DisplayName', $v));
  97. }
  98. if (null !== $v = $this->emailAddress) {
  99. $node->appendChild($document->createElement('EmailAddress', $v));
  100. }
  101. if (null !== $v = $this->id) {
  102. $node->appendChild($document->createElement('ID', $v));
  103. }
  104. if (null === $v = $this->type) {
  105. throw new InvalidArgument(sprintf('Missing parameter "Type" for "%s". The value cannot be null.', __CLASS__));
  106. }
  107. if (!Type::exists($v)) {
  108. throw new InvalidArgument(sprintf('Invalid parameter "xsi:type" for "%s". The value "%s" is not a valid "Type".', __CLASS__, $v));
  109. }
  110. $node->setAttribute('xsi:type', $v);
  111. if (null !== $v = $this->uri) {
  112. $node->appendChild($document->createElement('URI', $v));
  113. }
  114. }
  115. }