TopicConfiguration.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. namespace AsyncAws\S3\ValueObject;
  3. use AsyncAws\Core\Exception\InvalidArgument;
  4. use AsyncAws\S3\Enum\Event;
  5. /**
  6. * A container for specifying the configuration for publication of messages to an Amazon Simple Notification Service
  7. * (Amazon SNS) topic when Amazon S3 detects specified events.
  8. */
  9. final class TopicConfiguration
  10. {
  11. private $id;
  12. /**
  13. * The Amazon Resource Name (ARN) of the Amazon SNS topic to which Amazon S3 publishes a message when it detects events
  14. * of the specified type.
  15. */
  16. private $topicArn;
  17. /**
  18. * The Amazon S3 bucket event about which to send notifications. For more information, see Supported Event Types [^1] in
  19. * the *Amazon S3 User Guide*.
  20. *
  21. * [^1]: https://docs.aws.amazon.com/AmazonS3/latest/dev/NotificationHowTo.html
  22. */
  23. private $events;
  24. private $filter;
  25. /**
  26. * @param array{
  27. * Id?: null|string,
  28. * TopicArn: string,
  29. * Events: list<Event::*>,
  30. * Filter?: null|NotificationConfigurationFilter|array,
  31. * } $input
  32. */
  33. public function __construct(array $input)
  34. {
  35. $this->id = $input['Id'] ?? null;
  36. $this->topicArn = $input['TopicArn'] ?? null;
  37. $this->events = $input['Events'] ?? null;
  38. $this->filter = isset($input['Filter']) ? NotificationConfigurationFilter::create($input['Filter']) : null;
  39. }
  40. public static function create($input): self
  41. {
  42. return $input instanceof self ? $input : new self($input);
  43. }
  44. /**
  45. * @return list<Event::*>
  46. */
  47. public function getEvents(): array
  48. {
  49. return $this->events ?? [];
  50. }
  51. public function getFilter(): ?NotificationConfigurationFilter
  52. {
  53. return $this->filter;
  54. }
  55. public function getId(): ?string
  56. {
  57. return $this->id;
  58. }
  59. public function getTopicArn(): string
  60. {
  61. return $this->topicArn;
  62. }
  63. /**
  64. * @internal
  65. */
  66. public function requestBody(\DOMElement $node, \DOMDocument $document): void
  67. {
  68. if (null !== $v = $this->id) {
  69. $node->appendChild($document->createElement('Id', $v));
  70. }
  71. if (null === $v = $this->topicArn) {
  72. throw new InvalidArgument(sprintf('Missing parameter "TopicArn" for "%s". The value cannot be null.', __CLASS__));
  73. }
  74. $node->appendChild($document->createElement('Topic', $v));
  75. if (null === $v = $this->events) {
  76. throw new InvalidArgument(sprintf('Missing parameter "Events" for "%s". The value cannot be null.', __CLASS__));
  77. }
  78. foreach ($v as $item) {
  79. if (!Event::exists($item)) {
  80. throw new InvalidArgument(sprintf('Invalid parameter "Event" for "%s". The value "%s" is not a valid "Event".', __CLASS__, $item));
  81. }
  82. $node->appendChild($document->createElement('Event', $item));
  83. }
  84. if (null !== $v = $this->filter) {
  85. $node->appendChild($child = $document->createElement('Filter'));
  86. $v->requestBody($child, $document);
  87. }
  88. }
  89. }