MkCol.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. declare(strict_types=1);
  3. namespace Sabre\DAV\Xml\Request;
  4. use Sabre\Xml\Reader;
  5. use Sabre\Xml\XmlDeserializable;
  6. /**
  7. * WebDAV Extended MKCOL request parser.
  8. *
  9. * This class parses the {DAV:}mkol request, as defined in:
  10. *
  11. * https://tools.ietf.org/html/rfc5689#section-5.1
  12. *
  13. * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
  14. * @author Evert Pot (http://evertpot.com/)
  15. * @license http://sabre.io/license/ Modified BSD License
  16. */
  17. class MkCol implements XmlDeserializable
  18. {
  19. /**
  20. * The list of properties that will be set.
  21. *
  22. * @var array
  23. */
  24. protected $properties = [];
  25. /**
  26. * Returns a key=>value array with properties that are supposed to get set
  27. * during creation of the new collection.
  28. *
  29. * @return array
  30. */
  31. public function getProperties()
  32. {
  33. return $this->properties;
  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. $self = new self();
  58. $elementMap = $reader->elementMap;
  59. $elementMap['{DAV:}prop'] = 'Sabre\DAV\Xml\Element\Prop';
  60. $elementMap['{DAV:}set'] = 'Sabre\Xml\Element\KeyValue';
  61. $elementMap['{DAV:}remove'] = 'Sabre\Xml\Element\KeyValue';
  62. $elems = $reader->parseInnerTree($elementMap);
  63. foreach ($elems as $elem) {
  64. if ('{DAV:}set' === $elem['name']) {
  65. $self->properties = array_merge($self->properties, $elem['value']['{DAV:}prop']);
  66. }
  67. }
  68. return $self;
  69. }
  70. }