ShareRequest.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\DAV\DAV\Sharing\Xml;
  8. use OCA\DAV\DAV\Sharing\Plugin;
  9. use Sabre\Xml\Reader;
  10. use Sabre\Xml\XmlDeserializable;
  11. class ShareRequest implements XmlDeserializable {
  12. public $set = [];
  13. public $remove = [];
  14. /**
  15. * Constructor
  16. *
  17. * @param array $set
  18. * @param array $remove
  19. */
  20. public function __construct(array $set, array $remove) {
  21. $this->set = $set;
  22. $this->remove = $remove;
  23. }
  24. public static function xmlDeserialize(Reader $reader) {
  25. $elements = $reader->parseInnerTree([
  26. '{' . Plugin::NS_OWNCLOUD. '}set' => 'Sabre\\Xml\\Element\\KeyValue',
  27. '{' . Plugin::NS_OWNCLOUD . '}remove' => 'Sabre\\Xml\\Element\\KeyValue',
  28. ]);
  29. $set = [];
  30. $remove = [];
  31. foreach ($elements as $elem) {
  32. switch ($elem['name']) {
  33. case '{' . Plugin::NS_OWNCLOUD . '}set':
  34. $sharee = $elem['value'];
  35. $sumElem = '{' . Plugin::NS_OWNCLOUD . '}summary';
  36. $commonName = '{' . Plugin::NS_OWNCLOUD . '}common-name';
  37. $set[] = [
  38. 'href' => $sharee['{DAV:}href'],
  39. 'commonName' => $sharee[$commonName] ?? null,
  40. 'summary' => $sharee[$sumElem] ?? null,
  41. 'readOnly' => !array_key_exists('{' . Plugin::NS_OWNCLOUD . '}read-write', $sharee),
  42. ];
  43. break;
  44. case '{' . Plugin::NS_OWNCLOUD . '}remove':
  45. $remove[] = $elem['value']['{DAV:}href'];
  46. break;
  47. }
  48. }
  49. return new self($set, $remove);
  50. }
  51. }