ChecksumList.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Roeland Jago Douma <roeland@famdouma.nl>
  7. *
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. namespace OCA\DAV\Connector\Sabre;
  24. use Sabre\Xml\Writer;
  25. use Sabre\Xml\XmlSerializable;
  26. /**
  27. * Checksumlist property
  28. *
  29. * This property contains multiple "checksum" elements, each containing a
  30. * checksum name.
  31. */
  32. class ChecksumList implements XmlSerializable {
  33. public const NS_OWNCLOUD = 'http://owncloud.org/ns';
  34. /** @var string[] of TYPE:CHECKSUM */
  35. private array $checksums;
  36. public function __construct(string $checksum) {
  37. $this->checksums = explode(' ', $checksum);
  38. }
  39. /**
  40. * The xmlSerialize method is called during xml writing.
  41. *
  42. * Use the $writer argument to write its own xml serialization.
  43. *
  44. * An important note: do _not_ create a parent element. Any element
  45. * implementing XmlSerializble should only ever write what's considered
  46. * its 'inner xml'.
  47. *
  48. * The parent of the current element is responsible for writing a
  49. * containing element.
  50. *
  51. * This allows serializers to be re-used for different element names.
  52. *
  53. * If you are opening new elements, you must also close them again.
  54. *
  55. * @param Writer $writer
  56. * @return void
  57. */
  58. public function xmlSerialize(Writer $writer) {
  59. foreach ($this->checksums as $checksum) {
  60. $writer->writeElement('{' . self::NS_OWNCLOUD . '}checksum', $checksum);
  61. }
  62. }
  63. }