1 <?php
2 
3 namespace Sabre\DAVACL\Xml\Request;
4 
5 use Sabre\Xml\Deserializer;
6 use Sabre\Xml\Reader;
7 use Sabre\Xml\XmlDeserializable;
8 
9 /**
10  * PrincipalMatchReport request parser.
11  *
12  * This class parses the {DAV:}principal-match REPORT, as defined
13  * in:
14  *
15  * https://tools.ietf.org/html/rfc3744#section-9.3
16  *
17  * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
18  * @author Evert Pot (http://evertpot.com/)
19  * @license http://sabre.io/license/ Modified BSD License
20  */
21 class PrincipalMatchReport implements XmlDeserializable {
22 
23     /**
24      * Report on a list of principals that match the current principal.
25      */
26     const SELF = 1;
27 
28     /**
29      * Report on a property on resources, such as {DAV:}owner, that match the current principal.
30      */
31     const PRINCIPAL_PROPERTY = 2;
32 
33     /**
34      * Must be SELF or PRINCIPAL_PROPERTY
35      *
36      * @var int
37      */
38     public $type;
39 
40     /**
41      * List of properties that are being requested for matching resources.
42      *
43      * @var string[]
44      */
45     public $properties = [];
46 
47     /**
48      * If $type = PRINCIPAL_PROPERTY, which WebDAV property we should compare
49      * to the current principal.
50      *
51      * @var string
52      */
53     public $principalProperty;
54 
55     /**
56      * The deserialize method is called during xml parsing.
57      *
58      * This method is called statically, this is because in theory this method
59      * may be used as a type of constructor, or factory method.
60      *
61      * Often you want to return an instance of the current class, but you are
62      * free to return other data as well.
63      *
64      * You are responsible for advancing the reader to the next element. Not
65      * doing anything will result in a never-ending loop.
66      *
67      * If you just want to skip parsing for this element altogether, you can
68      * just call $reader->next();
69      *
70      * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
71      * the next element.
72      *
73      * @param Reader $reader
74      * @return mixed
75      */
76     static function xmlDeserialize(Reader $reader) {
77 
78         $reader->pushContext();
79         $reader->elementMap['{DAV:}prop'] = 'Sabre\Xml\Deserializer\enum';
80 
81         $elems = Deserializer\keyValue(
82             $reader,
83             'DAV:'
84         );
85 
86         $reader->popContext();
87 
88         $principalMatch = new self();
89 
90         if (array_key_exists('self', $elems)) {
91             $principalMatch->type = self::SELF;
92         }
93 
94         if (array_key_exists('principal-property', $elems)) {
95             $principalMatch->type = self::PRINCIPAL_PROPERTY;
96             $principalMatch->principalProperty = $elems['principal-property'][0]['name'];
97         }
98 
99         if (!empty($elems['prop'])) {
100             $principalMatch->properties = $elems['prop'];
101         }
102 
103         return $principalMatch;
104 
105     }
106 
107 }
108