ChecksumList.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 $checksums;
  36. /**
  37. * @param string $checksum
  38. */
  39. public function __construct($checksum) {
  40. $this->checksums = explode(',', $checksum);
  41. }
  42. /**
  43. * The xmlSerialize metod is called during xml writing.
  44. *
  45. * Use the $writer argument to write its own xml serialization.
  46. *
  47. * An important note: do _not_ create a parent element. Any element
  48. * implementing XmlSerializble should only ever write what's considered
  49. * its 'inner xml'.
  50. *
  51. * The parent of the current element is responsible for writing a
  52. * containing element.
  53. *
  54. * This allows serializers to be re-used for different element names.
  55. *
  56. * If you are opening new elements, you must also close them again.
  57. *
  58. * @param Writer $writer
  59. * @return void
  60. */
  61. public function xmlSerialize(Writer $writer) {
  62. foreach ($this->checksums as $checksum) {
  63. $writer->writeElement('{' . self::NS_OWNCLOUD . '}checksum', $checksum);
  64. }
  65. }
  66. }