1<?php
2
3namespace Sabre\DAV\Xml\Request;
4
5use Sabre\Xml\Reader;
6use Sabre\Xml\XmlDeserializable;
7
8/**
9 * WebDAV Extended MKCOL request parser.
10 *
11 * This class parses the {DAV:}mkol request, as defined in:
12 *
13 * https://tools.ietf.org/html/rfc5689#section-5.1
14 *
15 * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
16 * @author Evert Pot (http://evertpot.com/)
17 * @license http://sabre.io/license/ Modified BSD License
18 */
19class MkCol implements XmlDeserializable {
20
21    /**
22     * The list of properties that will be set.
23     *
24     * @var array
25     */
26    protected $properties = [];
27
28    /**
29     * Returns a key=>value array with properties that are supposed to get set
30     * during creation of the new collection.
31     *
32     * @return array
33     */
34    function getProperties() {
35
36        return $this->properties;
37
38    }
39
40    /**
41     * The deserialize method is called during xml parsing.
42     *
43     * This method is called statically, this is because in theory this method
44     * may be used as a type of constructor, or factory method.
45     *
46     * Often you want to return an instance of the current class, but you are
47     * free to return other data as well.
48     *
49     * You are responsible for advancing the reader to the next element. Not
50     * doing anything will result in a never-ending loop.
51     *
52     * If you just want to skip parsing for this element altogether, you can
53     * just call $reader->next();
54     *
55     * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
56     * the next element.
57     *
58     * @param Reader $reader
59     * @return mixed
60     */
61    static function xmlDeserialize(Reader $reader) {
62
63        $self = new self();
64
65        $elementMap = $reader->elementMap;
66        $elementMap['{DAV:}prop'] = 'Sabre\DAV\Xml\Element\Prop';
67        $elementMap['{DAV:}set'] = 'Sabre\Xml\Element\KeyValue';
68        $elementMap['{DAV:}remove'] = 'Sabre\Xml\Element\KeyValue';
69
70        $elems = $reader->parseInnerTree($elementMap);
71
72        foreach ($elems as $elem) {
73            if ($elem['name'] === '{DAV:}set') {
74                $self->properties = array_merge($self->properties, $elem['value']['{DAV:}prop']);
75            }
76        }
77
78        return $self;
79
80    }
81
82}
83