ChecksumList.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Roeland Jago Douma <roeland@famdouma.nl>
  6. *
  7. * @license AGPL-3.0
  8. *
  9. * This code is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License, version 3,
  11. * as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License, version 3,
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>
  20. *
  21. */
  22. namespace OCA\DAV\Connector\Sabre;
  23. use Sabre\Xml\XmlSerializable;
  24. use Sabre\Xml\Element;
  25. use Sabre\Xml\Writer;
  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. 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. function xmlSerialize(Writer $writer) {
  62. foreach ($this->checksums as $checksum) {
  63. $writer->writeElement('{' . self::NS_OWNCLOUD . '}checksum', $checksum);
  64. }
  65. }
  66. }