Publisher.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OCA\DAV\CalDAV\Publishing\Xml;
  7. use Sabre\Xml\Writer;
  8. use Sabre\Xml\XmlSerializable;
  9. class Publisher implements XmlSerializable {
  10. /**
  11. * @param string $publishUrl
  12. * @param boolean $isPublished
  13. */
  14. public function __construct(
  15. protected $publishUrl,
  16. protected $isPublished,
  17. ) {
  18. }
  19. /**
  20. * @return string
  21. */
  22. public function getValue() {
  23. return $this->publishUrl;
  24. }
  25. /**
  26. * The xmlSerialize method is called during xml writing.
  27. *
  28. * Use the $writer argument to write its own xml serialization.
  29. *
  30. * An important note: do _not_ create a parent element. Any element
  31. * implementing XmlSerializble should only ever write what's considered
  32. * its 'inner xml'.
  33. *
  34. * The parent of the current element is responsible for writing a
  35. * containing element.
  36. *
  37. * This allows serializers to be re-used for different element names.
  38. *
  39. * If you are opening new elements, you must also close them again.
  40. *
  41. * @param Writer $writer
  42. * @return void
  43. */
  44. public function xmlSerialize(Writer $writer) {
  45. if (!$this->isPublished) {
  46. // for pre-publish-url
  47. $writer->write($this->publishUrl);
  48. } else {
  49. // for publish-url
  50. $writer->writeElement('{DAV:}href', $this->publishUrl);
  51. }
  52. }
  53. }