ShareRequest.php 2.5 KB

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