ShareRequest.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. /**
  13. * Constructor
  14. *
  15. * @param array $set
  16. * @param array $remove
  17. */
  18. public function __construct(
  19. public array $set,
  20. public array $remove,
  21. ) {
  22. }
  23. public static function xmlDeserialize(Reader $reader) {
  24. $elements = $reader->parseInnerTree([
  25. '{' . Plugin::NS_OWNCLOUD . '}set' => 'Sabre\\Xml\\Element\\KeyValue',
  26. '{' . Plugin::NS_OWNCLOUD . '}remove' => 'Sabre\\Xml\\Element\\KeyValue',
  27. ]);
  28. $set = [];
  29. $remove = [];
  30. foreach ($elements as $elem) {
  31. switch ($elem['name']) {
  32. case '{' . Plugin::NS_OWNCLOUD . '}set':
  33. $sharee = $elem['value'];
  34. $sumElem = '{' . Plugin::NS_OWNCLOUD . '}summary';
  35. $commonName = '{' . Plugin::NS_OWNCLOUD . '}common-name';
  36. $set[] = [
  37. 'href' => $sharee['{DAV:}href'],
  38. 'commonName' => $sharee[$commonName] ?? null,
  39. 'summary' => $sharee[$sumElem] ?? null,
  40. 'readOnly' => !array_key_exists('{' . Plugin::NS_OWNCLOUD . '}read-write', $sharee),
  41. ];
  42. break;
  43. case '{' . Plugin::NS_OWNCLOUD . '}remove':
  44. $remove[] = $elem['value']['{DAV:}href'];
  45. break;
  46. }
  47. }
  48. return new self($set, $remove);
  49. }
  50. }