AllowedSharingModes.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. declare(strict_types=1);
  3. namespace Sabre\CalDAV\Xml\Property;
  4. use Sabre\CalDAV\Plugin;
  5. use Sabre\Xml\Writer;
  6. use Sabre\Xml\XmlSerializable;
  7. /**
  8. * AllowedSharingModes.
  9. *
  10. * This property encodes the 'allowed-sharing-modes' property, as defined by
  11. * the 'caldav-sharing-02' spec, in the http://calendarserver.org/ns/
  12. * namespace.
  13. *
  14. * This property is a representation of the supported-calendar_component-set
  15. * property in the CalDAV namespace. It simply requires an array of components,
  16. * such as VEVENT, VTODO
  17. *
  18. * @see https://trac.calendarserver.org/browser/CalendarServer/trunk/doc/Extensions/caldav-sharing-02.txt
  19. *
  20. * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
  21. * @author Evert Pot (http://www.rooftopsolutions.nl/)
  22. * @license http://sabre.io/license/ Modified BSD License
  23. */
  24. class AllowedSharingModes implements XmlSerializable
  25. {
  26. /**
  27. * Whether or not a calendar can be shared with another user.
  28. *
  29. * @var bool
  30. */
  31. protected $canBeShared;
  32. /**
  33. * Whether or not the calendar can be placed on a public url.
  34. *
  35. * @var bool
  36. */
  37. protected $canBePublished;
  38. /**
  39. * Constructor.
  40. *
  41. * @param bool $canBeShared
  42. * @param bool $canBePublished
  43. */
  44. public function __construct($canBeShared, $canBePublished)
  45. {
  46. $this->canBeShared = $canBeShared;
  47. $this->canBePublished = $canBePublished;
  48. }
  49. /**
  50. * The xmlSerialize method 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 XmlSerializable 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. public function xmlSerialize(Writer $writer)
  66. {
  67. if ($this->canBeShared) {
  68. $writer->writeElement('{'.Plugin::NS_CALENDARSERVER.'}can-be-shared');
  69. }
  70. if ($this->canBePublished) {
  71. $writer->writeElement('{'.Plugin::NS_CALENDARSERVER.'}can-be-published');
  72. }
  73. }
  74. }