ShareRequest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Roeland Jago Douma <roeland@famdouma.nl>
  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. function __construct(array $set, array $remove) {
  37. $this->set = $set;
  38. $this->remove = $remove;
  39. }
  40. 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' => isset($sharee[$commonName]) ? $sharee[$commonName] : null,
  56. 'summary' => isset($sharee[$sumElem]) ? $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. }