Publisher.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016 Thomas Citharel <tcit@tcit.fr>
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Thomas Citharel <nextcloud@tcit.fr>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCA\DAV\CalDAV\Publishing\Xml;
  25. use Sabre\Xml\Writer;
  26. use Sabre\Xml\XmlSerializable;
  27. class Publisher implements XmlSerializable {
  28. /**
  29. * @var string $publishUrl
  30. */
  31. protected $publishUrl;
  32. /**
  33. * @var boolean $isPublished
  34. */
  35. protected $isPublished;
  36. /**
  37. * @param string $publishUrl
  38. * @param boolean $isPublished
  39. */
  40. public function __construct($publishUrl, $isPublished) {
  41. $this->publishUrl = $publishUrl;
  42. $this->isPublished = $isPublished;
  43. }
  44. /**
  45. * @return string
  46. */
  47. public function getValue() {
  48. return $this->publishUrl;
  49. }
  50. /**
  51. * The xmlSerialize method is called during xml writing.
  52. *
  53. * Use the $writer argument to write its own xml serialization.
  54. *
  55. * An important note: do _not_ create a parent element. Any element
  56. * implementing XmlSerializble should only ever write what's considered
  57. * its 'inner xml'.
  58. *
  59. * The parent of the current element is responsible for writing a
  60. * containing element.
  61. *
  62. * This allows serializers to be re-used for different element names.
  63. *
  64. * If you are opening new elements, you must also close them again.
  65. *
  66. * @param Writer $writer
  67. * @return void
  68. */
  69. public function xmlSerialize(Writer $writer) {
  70. if (!$this->isPublished) {
  71. // for pre-publish-url
  72. $writer->write($this->publishUrl);
  73. } else {
  74. // for publish-url
  75. $writer->writeElement('{DAV:}href', $this->publishUrl);
  76. }
  77. }
  78. }