ShareResource.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. declare(strict_types=1);
  3. namespace Sabre\DAV\Xml\Request;
  4. use Sabre\DAV\Xml\Element\Sharee;
  5. use Sabre\Xml\Reader;
  6. use Sabre\Xml\XmlDeserializable;
  7. /**
  8. * ShareResource request parser.
  9. *
  10. * This class parses the {DAV:}share-resource POST request as defined in:
  11. *
  12. * https://tools.ietf.org/html/draft-pot-webdav-resource-sharing-01#section-5.3.2.1
  13. *
  14. * @copyright Copyright (C) 2007-2015 fruux GmbH (https://fruux.com/).
  15. * @author Evert Pot (http://www.rooftopsolutions.nl/)
  16. * @license http://sabre.io/license/ Modified BSD License
  17. */
  18. class ShareResource implements XmlDeserializable
  19. {
  20. /**
  21. * The list of new people added or updated or removed from the share.
  22. *
  23. * @var Sharee[]
  24. */
  25. public $sharees = [];
  26. /**
  27. * Constructor.
  28. *
  29. * @param Sharee[] $sharees
  30. */
  31. public function __construct(array $sharees)
  32. {
  33. $this->sharees = $sharees;
  34. }
  35. /**
  36. * The deserialize method is called during xml parsing.
  37. *
  38. * This method is called statically, this is because in theory this method
  39. * may be used as a type of constructor, or factory method.
  40. *
  41. * Often you want to return an instance of the current class, but you are
  42. * free to return other data as well.
  43. *
  44. * You are responsible for advancing the reader to the next element. Not
  45. * doing anything will result in a never-ending loop.
  46. *
  47. * If you just want to skip parsing for this element altogether, you can
  48. * just call $reader->next();
  49. *
  50. * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
  51. * the next element.
  52. *
  53. * @return mixed
  54. */
  55. public static function xmlDeserialize(Reader $reader)
  56. {
  57. $elems = $reader->parseInnerTree([
  58. '{DAV:}sharee' => 'Sabre\DAV\Xml\Element\Sharee',
  59. '{DAV:}share-access' => 'Sabre\DAV\Xml\Property\ShareAccess',
  60. '{DAV:}prop' => 'Sabre\Xml\Deserializer\keyValue',
  61. ]);
  62. $sharees = [];
  63. foreach ($elems as $elem) {
  64. if ('{DAV:}sharee' !== $elem['name']) {
  65. continue;
  66. }
  67. $sharees[] = $elem['value'];
  68. }
  69. return new self($sharees);
  70. }
  71. }