Delete.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace AsyncAws\S3\ValueObject;
  3. use AsyncAws\Core\Exception\InvalidArgument;
  4. /**
  5. * Container for the objects to delete.
  6. */
  7. final class Delete
  8. {
  9. /**
  10. * The object to delete.
  11. */
  12. private $objects;
  13. /**
  14. * Element to enable quiet mode for the request. When you add this element, you must set its value to true.
  15. */
  16. private $quiet;
  17. /**
  18. * @param array{
  19. * Objects: ObjectIdentifier[],
  20. * Quiet?: null|bool,
  21. * } $input
  22. */
  23. public function __construct(array $input)
  24. {
  25. $this->objects = isset($input['Objects']) ? array_map([ObjectIdentifier::class, 'create'], $input['Objects']) : null;
  26. $this->quiet = $input['Quiet'] ?? null;
  27. }
  28. public static function create($input): self
  29. {
  30. return $input instanceof self ? $input : new self($input);
  31. }
  32. /**
  33. * @return ObjectIdentifier[]
  34. */
  35. public function getObjects(): array
  36. {
  37. return $this->objects ?? [];
  38. }
  39. public function getQuiet(): ?bool
  40. {
  41. return $this->quiet;
  42. }
  43. /**
  44. * @internal
  45. */
  46. public function requestBody(\DOMElement $node, \DOMDocument $document): void
  47. {
  48. if (null === $v = $this->objects) {
  49. throw new InvalidArgument(sprintf('Missing parameter "Objects" for "%s". The value cannot be null.', __CLASS__));
  50. }
  51. foreach ($v as $item) {
  52. $node->appendChild($child = $document->createElement('Object'));
  53. $item->requestBody($child, $document);
  54. }
  55. if (null !== $v = $this->quiet) {
  56. $node->appendChild($document->createElement('Quiet', $v ? 'true' : 'false'));
  57. }
  58. }
  59. }