ChecksumList.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\DAV\Connector\Sabre;
  8. use Sabre\Xml\Writer;
  9. use Sabre\Xml\XmlSerializable;
  10. /**
  11. * Checksumlist property
  12. *
  13. * This property contains multiple "checksum" elements, each containing a
  14. * checksum name.
  15. */
  16. class ChecksumList implements XmlSerializable {
  17. public const NS_OWNCLOUD = 'http://owncloud.org/ns';
  18. /** @var string[] of TYPE:CHECKSUM */
  19. private array $checksums;
  20. public function __construct(string $checksum) {
  21. $this->checksums = explode(' ', $checksum);
  22. }
  23. /**
  24. * The xmlSerialize method is called during xml writing.
  25. *
  26. * Use the $writer argument to write its own xml serialization.
  27. *
  28. * An important note: do _not_ create a parent element. Any element
  29. * implementing XmlSerializble should only ever write what's considered
  30. * its 'inner xml'.
  31. *
  32. * The parent of the current element is responsible for writing a
  33. * containing element.
  34. *
  35. * This allows serializers to be re-used for different element names.
  36. *
  37. * If you are opening new elements, you must also close them again.
  38. *
  39. * @param Writer $writer
  40. * @return void
  41. */
  42. public function xmlSerialize(Writer $writer) {
  43. foreach ($this->checksums as $checksum) {
  44. $writer->writeElement('{' . self::NS_OWNCLOUD . '}checksum', $checksum);
  45. }
  46. }
  47. }