InviteReply.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. declare(strict_types=1);
  3. namespace Sabre\CalDAV\Xml\Request;
  4. use Sabre\CalDAV\Plugin;
  5. use Sabre\CalDAV\SharingPlugin;
  6. use Sabre\DAV;
  7. use Sabre\DAV\Exception\BadRequest;
  8. use Sabre\Xml\Element\KeyValue;
  9. use Sabre\Xml\Reader;
  10. use Sabre\Xml\XmlDeserializable;
  11. /**
  12. * Invite-reply POST request parser.
  13. *
  14. * This class parses the invite-reply POST request, as defined in:
  15. *
  16. * http://svn.calendarserver.org/repository/calendarserver/CalendarServer/trunk/doc/Extensions/caldav-sharing.txt
  17. *
  18. * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
  19. * @author Evert Pot (http://evertpot.com/)
  20. * @license http://sabre.io/license/ Modified BSD License
  21. */
  22. class InviteReply implements XmlDeserializable
  23. {
  24. /**
  25. * The sharee calendar user address.
  26. *
  27. * This is the address that the original invite was set to
  28. *
  29. * @var string
  30. */
  31. public $href;
  32. /**
  33. * The uri to the calendar that was being shared.
  34. *
  35. * @var string
  36. */
  37. public $calendarUri;
  38. /**
  39. * The id of the invite message that's being responded to.
  40. *
  41. * @var string
  42. */
  43. public $inReplyTo;
  44. /**
  45. * An optional message.
  46. *
  47. * @var string
  48. */
  49. public $summary;
  50. /**
  51. * Either SharingPlugin::STATUS_ACCEPTED or SharingPlugin::STATUS_DECLINED.
  52. *
  53. * @var int
  54. */
  55. public $status;
  56. /**
  57. * Constructor.
  58. *
  59. * @param string $href
  60. * @param string $calendarUri
  61. * @param string $inReplyTo
  62. * @param string $summary
  63. * @param int $status
  64. */
  65. public function __construct($href, $calendarUri, $inReplyTo, $summary, $status)
  66. {
  67. $this->href = $href;
  68. $this->calendarUri = $calendarUri;
  69. $this->inReplyTo = $inReplyTo;
  70. $this->summary = $summary;
  71. $this->status = $status;
  72. }
  73. /**
  74. * The deserialize method is called during xml parsing.
  75. *
  76. * This method is called statically, this is because in theory this method
  77. * may be used as a type of constructor, or factory method.
  78. *
  79. * Often you want to return an instance of the current class, but you are
  80. * free to return other data as well.
  81. *
  82. * You are responsible for advancing the reader to the next element. Not
  83. * doing anything will result in a never-ending loop.
  84. *
  85. * If you just want to skip parsing for this element altogether, you can
  86. * just call $reader->next();
  87. *
  88. * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
  89. * the next element.
  90. *
  91. * @return mixed
  92. */
  93. public static function xmlDeserialize(Reader $reader)
  94. {
  95. $elems = KeyValue::xmlDeserialize($reader);
  96. $href = null;
  97. $calendarUri = null;
  98. $inReplyTo = null;
  99. $summary = null;
  100. $status = null;
  101. foreach ($elems as $name => $value) {
  102. switch ($name) {
  103. case '{'.Plugin::NS_CALENDARSERVER.'}hosturl':
  104. foreach ($value as $bla) {
  105. if ('{DAV:}href' === $bla['name']) {
  106. $calendarUri = $bla['value'];
  107. }
  108. }
  109. break;
  110. case '{'.Plugin::NS_CALENDARSERVER.'}invite-accepted':
  111. $status = DAV\Sharing\Plugin::INVITE_ACCEPTED;
  112. break;
  113. case '{'.Plugin::NS_CALENDARSERVER.'}invite-declined':
  114. $status = DAV\Sharing\Plugin::INVITE_DECLINED;
  115. break;
  116. case '{'.Plugin::NS_CALENDARSERVER.'}in-reply-to':
  117. $inReplyTo = $value;
  118. break;
  119. case '{'.Plugin::NS_CALENDARSERVER.'}summary':
  120. $summary = $value;
  121. break;
  122. case '{DAV:}href':
  123. $href = $value;
  124. break;
  125. }
  126. }
  127. if (is_null($calendarUri)) {
  128. throw new BadRequest('The {http://calendarserver.org/ns/}hosturl/{DAV:}href element must exist');
  129. }
  130. return new self($href, $calendarUri, $inReplyTo, $summary, $status);
  131. }
  132. }