You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ShareRequest.php 2.2KB

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