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