Publisher.php 2.2 KB

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