Publisher.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. * @var string $publishUrl
  12. */
  13. protected $publishUrl;
  14. /**
  15. * @var boolean $isPublished
  16. */
  17. protected $isPublished;
  18. /**
  19. * @param string $publishUrl
  20. * @param boolean $isPublished
  21. */
  22. public function __construct($publishUrl, $isPublished) {
  23. $this->publishUrl = $publishUrl;
  24. $this->isPublished = $isPublished;
  25. }
  26. /**
  27. * @return string
  28. */
  29. public function getValue() {
  30. return $this->publishUrl;
  31. }
  32. /**
  33. * The xmlSerialize method is called during xml writing.
  34. *
  35. * Use the $writer argument to write its own xml serialization.
  36. *
  37. * An important note: do _not_ create a parent element. Any element
  38. * implementing XmlSerializble should only ever write what's considered
  39. * its 'inner xml'.
  40. *
  41. * The parent of the current element is responsible for writing a
  42. * containing element.
  43. *
  44. * This allows serializers to be re-used for different element names.
  45. *
  46. * If you are opening new elements, you must also close them again.
  47. *
  48. * @param Writer $writer
  49. * @return void
  50. */
  51. public function xmlSerialize(Writer $writer) {
  52. if (!$this->isPublished) {
  53. // for pre-publish-url
  54. $writer->write($this->publishUrl);
  55. } else {
  56. // for publish-url
  57. $writer->writeElement('{DAV:}href', $this->publishUrl);
  58. }
  59. }
  60. }