Share.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. declare(strict_types=1);
  3. namespace Sabre\CalDAV\Xml\Request;
  4. use Sabre\CalDAV\Plugin;
  5. use Sabre\DAV\Xml\Element\Sharee;
  6. use Sabre\Xml\Reader;
  7. use Sabre\Xml\XmlDeserializable;
  8. /**
  9. * Share POST request parser.
  10. *
  11. * This class parses the share POST request, as defined in:
  12. *
  13. * http://svn.calendarserver.org/repository/calendarserver/CalendarServer/trunk/doc/Extensions/caldav-sharing.txt
  14. *
  15. * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
  16. * @author Evert Pot (http://evertpot.com/)
  17. * @license http://sabre.io/license/ Modified BSD License
  18. */
  19. class Share implements XmlDeserializable
  20. {
  21. /**
  22. * The list of new people added or updated or removed from the share.
  23. *
  24. * @var Sharee[]
  25. */
  26. public $sharees = [];
  27. /**
  28. * Constructor.
  29. *
  30. * @param Sharee[] $sharees
  31. */
  32. public function __construct(array $sharees)
  33. {
  34. $this->sharees = $sharees;
  35. }
  36. /**
  37. * The deserialize method is called during xml parsing.
  38. *
  39. * This method is called statically, this is because in theory this method
  40. * may be used as a type of constructor, or factory method.
  41. *
  42. * Often you want to return an instance of the current class, but you are
  43. * free to return other data as well.
  44. *
  45. * You are responsible for advancing the reader to the next element. Not
  46. * doing anything will result in a never-ending loop.
  47. *
  48. * If you just want to skip parsing for this element altogether, you can
  49. * just call $reader->next();
  50. *
  51. * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
  52. * the next element.
  53. *
  54. * @return mixed
  55. */
  56. public static function xmlDeserialize(Reader $reader)
  57. {
  58. $elems = $reader->parseGetElements([
  59. '{'.Plugin::NS_CALENDARSERVER.'}set' => 'Sabre\\Xml\\Element\\KeyValue',
  60. '{'.Plugin::NS_CALENDARSERVER.'}remove' => 'Sabre\\Xml\\Element\\KeyValue',
  61. ]);
  62. $sharees = [];
  63. foreach ($elems as $elem) {
  64. switch ($elem['name']) {
  65. case '{'.Plugin::NS_CALENDARSERVER.'}set':
  66. $sharee = $elem['value'];
  67. $sumElem = '{'.Plugin::NS_CALENDARSERVER.'}summary';
  68. $commonName = '{'.Plugin::NS_CALENDARSERVER.'}common-name';
  69. $properties = [];
  70. if (isset($sharee[$commonName])) {
  71. $properties['{DAV:}displayname'] = $sharee[$commonName];
  72. }
  73. $access = array_key_exists('{'.Plugin::NS_CALENDARSERVER.'}read-write', $sharee)
  74. ? \Sabre\DAV\Sharing\Plugin::ACCESS_READWRITE
  75. : \Sabre\DAV\Sharing\Plugin::ACCESS_READ;
  76. $sharees[] = new Sharee([
  77. 'href' => $sharee['{DAV:}href'],
  78. 'properties' => $properties,
  79. 'access' => $access,
  80. 'comment' => isset($sharee[$sumElem]) ? $sharee[$sumElem] : null,
  81. ]);
  82. break;
  83. case '{'.Plugin::NS_CALENDARSERVER.'}remove':
  84. $sharees[] = new Sharee([
  85. 'href' => $elem['value']['{DAV:}href'],
  86. 'access' => \Sabre\DAV\Sharing\Plugin::ACCESS_NOACCESS,
  87. ]);
  88. break;
  89. }
  90. }
  91. return new self($sharees);
  92. }
  93. }