ShareRequest.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Thomas Müller <thomas.mueller@tmit.eu>
  7. *
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. namespace OCA\DAV\DAV\Sharing\Xml;
  24. use OCA\DAV\DAV\Sharing\Plugin;
  25. use Sabre\Xml\Reader;
  26. use Sabre\Xml\XmlDeserializable;
  27. class ShareRequest implements XmlDeserializable {
  28. public $set = [];
  29. public $remove = [];
  30. /**
  31. * Constructor
  32. *
  33. * @param array $set
  34. * @param array $remove
  35. */
  36. public function __construct(array $set, array $remove) {
  37. $this->set = $set;
  38. $this->remove = $remove;
  39. }
  40. public static function xmlDeserialize(Reader $reader) {
  41. $elements = $reader->parseInnerTree([
  42. '{' . Plugin::NS_OWNCLOUD. '}set' => 'Sabre\\Xml\\Element\\KeyValue',
  43. '{' . Plugin::NS_OWNCLOUD . '}remove' => 'Sabre\\Xml\\Element\\KeyValue',
  44. ]);
  45. $set = [];
  46. $remove = [];
  47. foreach ($elements as $elem) {
  48. switch ($elem['name']) {
  49. case '{' . Plugin::NS_OWNCLOUD . '}set':
  50. $sharee = $elem['value'];
  51. $sumElem = '{' . Plugin::NS_OWNCLOUD . '}summary';
  52. $commonName = '{' . Plugin::NS_OWNCLOUD . '}common-name';
  53. $set[] = [
  54. 'href' => $sharee['{DAV:}href'],
  55. 'commonName' => $sharee[$commonName] ?? null,
  56. 'summary' => $sharee[$sumElem] ?? null,
  57. 'readOnly' => !array_key_exists('{' . Plugin::NS_OWNCLOUD . '}read-write', $sharee),
  58. ];
  59. break;
  60. case '{' . Plugin::NS_OWNCLOUD . '}remove':
  61. $remove[] = $elem['value']['{DAV:}href'];
  62. break;
  63. }
  64. }
  65. return new self($set, $remove);
  66. }
  67. }