Completed
Push — developer ( f9e515...68a04b )
by Błażej
506:11 queued 468:51
created
libraries/SabreDAV/DAVACL/Plugin.php 5 patches
Doc Comments   +9 added lines, -11 removed lines patch added patch discarded remove patch
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
      *
114 114
      * This list is used in the response of a HTTP OPTIONS request.
115 115
      *
116
-     * @return array
116
+     * @return string[]
117 117
      */
118 118
     function getFeatures() {
119 119
 
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
      * Returns a list of available methods for a given url
126 126
      *
127 127
      * @param string $uri
128
-     * @return array
128
+     * @return string[]
129 129
      */
130 130
     function getMethods($uri) {
131 131
 
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
      * implement them
156 156
      *
157 157
      * @param string $uri
158
-     * @return array
158
+     * @return string[]
159 159
      */
160 160
     function getSupportedReportSet($uri) {
161 161
 
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
      * and return true otherwise.
177 177
      *
178 178
      * @param string $uri
179
-     * @param array|string $privileges
179
+     * @param string $privileges
180 180
      * @param int $recursion
181 181
      * @param bool $throwExceptions if set to false, this method won't throw exceptions.
182 182
      * @throws Sabre\DAVACL\Exception\NeedPrivileges
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
     /**
270 270
      * Returns all the principal groups the specified principal is a member of.
271 271
      *
272
-     * @param string $principal
272
+     * @param string $mainPrincipal
273 273
      * @return array
274 274
      */
275 275
     function getPrincipalMembership($mainPrincipal) {
@@ -831,10 +831,8 @@  discard block
 block discarded – undo
831 831
      *
832 832
      * @param DAV\PropFind $propFind
833 833
      * @param DAV\INode $node
834
-     * @param array $requestedProperties
835
-     * @param array $returnedProperties
836 834
      * @TODO really should be broken into multiple methods, or even a class.
837
-     * @return bool
835
+     * @return false|null
838 836
      */
839 837
     function propFind(DAV\PropFind $propFind, DAV\INode $node) {
840 838
 
@@ -982,7 +980,7 @@  discard block
 block discarded – undo
982 980
      * @param string $reportName
983 981
      * @param mixed $report
984 982
      * @param mixed $path
985
-     * @return bool
983
+     * @return false|null
986 984
      */
987 985
     function report($reportName, $report, $path) {
988 986
 
@@ -1133,7 +1131,7 @@  discard block
 block discarded – undo
1133 1131
      * @param array $path
1134 1132
      * @param array $requestedProperties the list of required properties
1135 1133
      * @param int $depth
1136
-     * @return array
1134
+     * @return DAV\Xml\Element\Response[]
1137 1135
      */
1138 1136
     protected function expandProperties($path, array $requestedProperties, $depth) {
1139 1137
 
@@ -1278,7 +1276,7 @@  discard block
 block discarded – undo
1278 1276
      *
1279 1277
      * @param DAV\INode $node
1280 1278
      * @param string $output
1281
-     * @return bool
1279
+     * @return null|false
1282 1280
      */
1283 1281
     function htmlActionsPanel(DAV\INode $node, &$output) {
1284 1282
 
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -674,15 +674,15 @@
 block discarded – undo
674 674
     function initialize(DAV\Server $server) {
675 675
 
676 676
         $this->server = $server;
677
-        $server->on('propFind',            [$this, 'propFind'], 20);
678
-        $server->on('beforeMethod',        [$this, 'beforeMethod'], 20);
679
-        $server->on('beforeBind',          [$this, 'beforeBind'], 20);
680
-        $server->on('beforeUnbind',        [$this, 'beforeUnbind'], 20);
681
-        $server->on('propPatch',           [$this, 'propPatch']);
682
-        $server->on('beforeUnlock',        [$this, 'beforeUnlock'], 20);
683
-        $server->on('report',              [$this, 'report']);
684
-        $server->on('method:ACL',          [$this, 'httpAcl']);
685
-        $server->on('onHTMLActionsPanel',  [$this, 'htmlActionsPanel']);
677
+        $server->on('propFind', [$this, 'propFind'], 20);
678
+        $server->on('beforeMethod', [$this, 'beforeMethod'], 20);
679
+        $server->on('beforeBind', [$this, 'beforeBind'], 20);
680
+        $server->on('beforeUnbind', [$this, 'beforeUnbind'], 20);
681
+        $server->on('propPatch', [$this, 'propPatch']);
682
+        $server->on('beforeUnlock', [$this, 'beforeUnlock'], 20);
683
+        $server->on('report', [$this, 'report']);
684
+        $server->on('method:ACL', [$this, 'httpAcl']);
685
+        $server->on('onHTMLActionsPanel', [$this, 'htmlActionsPanel']);
686 686
 
687 687
         array_push($server->protectedProperties,
688 688
             '{DAV:}alternate-URI-set',
Please login to merge, or discard this patch.
Braces   +49 added lines, -25 removed lines patch added patch discarded remove patch
@@ -184,7 +184,9 @@  discard block
 block discarded – undo
184 184
      */
185 185
     function checkPrivileges($uri, $privileges, $recursion = self::R_PARENT, $throwExceptions = true) {
186 186
 
187
-        if (!is_array($privileges)) $privileges = [$privileges];
187
+        if (!is_array($privileges)) {
188
+        	$privileges = [$privileges];
189
+        }
188 190
 
189 191
         $acl = $this->getCurrentUserPrivilegeSet($uri);
190 192
 
@@ -192,10 +194,11 @@  discard block
 block discarded – undo
192 194
             if ($this->allowAccessToNodesWithoutACL) {
193 195
                 return true;
194 196
             } else {
195
-                if ($throwExceptions)
196
-                    throw new Exception\NeedPrivileges($uri, $privileges);
197
-                else
198
-                    return false;
197
+                if ($throwExceptions) {
198
+                                    throw new Exception\NeedPrivileges($uri, $privileges);
199
+                } else {
200
+                                    return false;
201
+                }
199 202
 
200 203
             }
201 204
         }
@@ -210,10 +213,11 @@  discard block
 block discarded – undo
210 213
         }
211 214
 
212 215
         if ($failed) {
213
-            if ($throwExceptions)
214
-                throw new Exception\NeedPrivileges($uri, $failed);
215
-            else
216
-                return false;
216
+            if ($throwExceptions) {
217
+                            throw new Exception\NeedPrivileges($uri, $failed);
218
+            } else {
219
+                            return false;
220
+            }
217 221
         }
218 222
         return true;
219 223
 
@@ -230,7 +234,9 @@  discard block
 block discarded – undo
230 234
     function getCurrentUserPrincipal() {
231 235
 
232 236
         $authPlugin = $this->server->getPlugin('auth');
233
-        if (is_null($authPlugin)) return null;
237
+        if (is_null($authPlugin)) {
238
+        	return null;
239
+        }
234 240
         /** @var $authPlugin Sabre\DAV\Auth\Plugin */
235 241
 
236 242
         return $authPlugin->getCurrentPrincipal();
@@ -248,7 +254,9 @@  discard block
 block discarded – undo
248 254
 
249 255
         $currentUser = $this->getCurrentUserPrincipal();
250 256
 
251
-        if (is_null($currentUser)) return [];
257
+        if (is_null($currentUser)) {
258
+        	return [];
259
+        }
252 260
 
253 261
         return array_merge(
254 262
             [$currentUser],
@@ -331,8 +339,9 @@  discard block
 block discarded – undo
331 339
         if ($node instanceof IACL) {
332 340
             $result = $node->getSupportedPrivilegeSet();
333 341
 
334
-            if ($result)
335
-                return $result;
342
+            if ($result) {
343
+                            return $result;
344
+            }
336 345
         }
337 346
 
338 347
         return self::getDefaultSupportedPrivilegeSet();
@@ -506,7 +515,9 @@  discard block
 block discarded – undo
506 515
 
507 516
         $acl = $this->getACL($node);
508 517
 
509
-        if (is_null($acl)) return null;
518
+        if (is_null($acl)) {
519
+        	return null;
520
+        }
510 521
 
511 522
         $principals = $this->getCurrentUserPrincipals();
512 523
 
@@ -730,7 +741,9 @@  discard block
 block discarded – undo
730 741
         $exists = $this->server->tree->nodeExists($path);
731 742
 
732 743
         // If the node doesn't exists, none of these checks apply
733
-        if (!$exists) return;
744
+        if (!$exists) {
745
+        	return;
746
+        }
734 747
 
735 748
         switch ($method) {
736 749
 
@@ -891,7 +904,9 @@  discard block
 block discarded – undo
891 904
 
892 905
             $val = $this->principalCollectionSet;
893 906
             // Ensuring all collections end with a slash
894
-            foreach ($val as $k => $v) $val[$k] = $v . '/';
907
+            foreach ($val as $k => $v) {
908
+            	$val[$k] = $v . '/';
909
+            }
895 910
             return new DAV\Xml\Property\Href($val);
896 911
 
897 912
         });
@@ -1042,7 +1057,9 @@  discard block
 block discarded – undo
1042 1057
            not overwritten. */
1043 1058
         foreach ($oldAcl as $oldAce) {
1044 1059
 
1045
-            if (!isset($oldAce['protected']) || !$oldAce['protected']) continue;
1060
+            if (!isset($oldAce['protected']) || !$oldAce['protected']) {
1061
+            	continue;
1062
+            }
1046 1063
 
1047 1064
             $found = false;
1048 1065
             foreach ($newAcl as $newAce) {
@@ -1050,12 +1067,14 @@  discard block
 block discarded – undo
1050 1067
                     $newAce['privilege'] === $oldAce['privilege'] &&
1051 1068
                     $newAce['principal'] === $oldAce['principal'] &&
1052 1069
                     $newAce['protected']
1053
-                )
1054
-                $found = true;
1070
+                ) {
1071
+                                $found = true;
1072
+                }
1055 1073
             }
1056 1074
 
1057
-            if (!$found)
1058
-                throw new Exception\AceConflict('This resource contained a protected {DAV:}ace, but this privilege did not occur in the ACL request');
1075
+            if (!$found) {
1076
+                            throw new Exception\AceConflict('This resource contained a protected {DAV:}ace, but this privilege did not occur in the ACL request');
1077
+            }
1059 1078
 
1060 1079
         }
1061 1080
 
@@ -1146,11 +1165,15 @@  discard block
 block discarded – undo
1146 1165
             foreach ($requestedProperties as $propertyName => $childRequestedProperties) {
1147 1166
 
1148 1167
                 // We're only traversing if sub-properties were requested
1149
-                if (count($childRequestedProperties) === 0) continue;
1168
+                if (count($childRequestedProperties) === 0) {
1169
+                	continue;
1170
+                }
1150 1171
 
1151 1172
                 // We only have to do the expansion if the property was found
1152 1173
                 // and it contains an href element.
1153
-                if (!array_key_exists($propertyName, $node[200])) continue;
1174
+                if (!array_key_exists($propertyName, $node[200])) {
1175
+                	continue;
1176
+                }
1154 1177
 
1155 1178
                 if (!$node[200][$propertyName] instanceof DAV\Xml\Property\Href) {
1156 1179
                     continue;
@@ -1282,8 +1305,9 @@  discard block
 block discarded – undo
1282 1305
      */
1283 1306
     function htmlActionsPanel(DAV\INode $node, &$output) {
1284 1307
 
1285
-        if (!$node instanceof PrincipalCollection)
1286
-            return;
1308
+        if (!$node instanceof PrincipalCollection) {
1309
+                    return;
1310
+        }
1287 1311
 
1288 1312
         $output .= '<tr><td colspan="2"><form method="post" action="">
1289 1313
             <h3>Create new principal</h3>
Please login to merge, or discard this patch.
Unused Use Statements   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -3,8 +3,8 @@
 block discarded – undo
3 3
 namespace Sabre\DAVACL;
4 4
 
5 5
 use Sabre\DAV;
6
-use Sabre\DAV\INode;
7 6
 use Sabre\DAV\Exception\BadRequest;
7
+use Sabre\DAV\INode;
8 8
 use Sabre\HTTP\RequestInterface;
9 9
 use Sabre\HTTP\ResponseInterface;
10 10
 use Sabre\Uri;
Please login to merge, or discard this patch.
Indentation   +1255 added lines, -1255 removed lines patch added patch discarded remove patch
@@ -25,1265 +25,1265 @@  discard block
 block discarded – undo
25 25
  */
26 26
 class Plugin extends DAV\ServerPlugin {
27 27
 
28
-    /**
29
-     * Recursion constants
30
-     *
31
-     * This only checks the base node
32
-     */
33
-    const R_PARENT = 1;
34
-
35
-    /**
36
-     * Recursion constants
37
-     *
38
-     * This checks every node in the tree
39
-     */
40
-    const R_RECURSIVE = 2;
41
-
42
-    /**
43
-     * Recursion constants
44
-     *
45
-     * This checks every parentnode in the tree, but not leaf-nodes.
46
-     */
47
-    const R_RECURSIVEPARENTS = 3;
48
-
49
-    /**
50
-     * Reference to server object.
51
-     *
52
-     * @var Sabre\DAV\Server
53
-     */
54
-    protected $server;
55
-
56
-    /**
57
-     * List of urls containing principal collections.
58
-     * Modify this if your principals are located elsewhere.
59
-     *
60
-     * @var array
61
-     */
62
-    public $principalCollectionSet = [
63
-        'principals',
64
-    ];
65
-
66
-    /**
67
-     * By default ACL is only enforced for nodes that have ACL support (the
68
-     * ones that implement IACL). For any other node, access is
69
-     * always granted.
70
-     *
71
-     * To override this behaviour you can turn this setting off. This is useful
72
-     * if you plan to fully support ACL in the entire tree.
73
-     *
74
-     * @var bool
75
-     */
76
-    public $allowAccessToNodesWithoutACL = true;
77
-
78
-    /**
79
-     * By default nodes that are inaccessible by the user, can still be seen
80
-     * in directory listings (PROPFIND on parent with Depth: 1)
81
-     *
82
-     * In certain cases it's desirable to hide inaccessible nodes. Setting this
83
-     * to true will cause these nodes to be hidden from directory listings.
84
-     *
85
-     * @var bool
86
-     */
87
-    public $hideNodesFromListings = false;
88
-
89
-    /**
90
-     * This list of properties are the properties a client can search on using
91
-     * the {DAV:}principal-property-search report.
92
-     *
93
-     * The keys are the property names, values are descriptions.
94
-     *
95
-     * @var array
96
-     */
97
-    public $principalSearchPropertySet = [
98
-        '{DAV:}displayname'                     => 'Display name',
99
-        '{http://sabredav.org/ns}email-address' => 'Email address',
100
-    ];
101
-
102
-    /**
103
-     * Any principal uri's added here, will automatically be added to the list
104
-     * of ACL's. They will effectively receive {DAV:}all privileges, as a
105
-     * protected privilege.
106
-     *
107
-     * @var array
108
-     */
109
-    public $adminPrincipals = [];
110
-
111
-    /**
112
-     * Returns a list of features added by this plugin.
113
-     *
114
-     * This list is used in the response of a HTTP OPTIONS request.
115
-     *
116
-     * @return array
117
-     */
118
-    public function getFeatures() {
119
-
120
-        return ['access-control', 'calendarserver-principal-property-search'];
121
-
122
-    }
123
-
124
-    /**
125
-     * Returns a list of available methods for a given url
126
-     *
127
-     * @param string $uri
128
-     * @return array
129
-     */
130
-    public function getMethods($uri) {
131
-
132
-        return ['ACL'];
133
-
134
-    }
135
-
136
-    /**
137
-     * Returns a plugin name.
138
-     *
139
-     * Using this name other plugins will be able to access other plugins
140
-     * using Sabre\DAV\Server::getPlugin
141
-     *
142
-     * @return string
143
-     */
144
-    public function getPluginName() {
145
-
146
-        return 'acl';
147
-
148
-    }
149
-
150
-    /**
151
-     * Returns a list of reports this plugin supports.
152
-     *
153
-     * This will be used in the {DAV:}supported-report-set property.
154
-     * Note that you still need to subscribe to the 'report' event to actually
155
-     * implement them
156
-     *
157
-     * @param string $uri
158
-     * @return array
159
-     */
160
-    public function getSupportedReportSet($uri) {
161
-
162
-        return [
163
-            '{DAV:}expand-property',
164
-            '{DAV:}principal-property-search',
165
-            '{DAV:}principal-search-property-set',
166
-        ];
167
-
168
-    }
169
-
170
-
171
-    /**
172
-     * Checks if the current user has the specified privilege(s).
173
-     *
174
-     * You can specify a single privilege, or a list of privileges.
175
-     * This method will throw an exception if the privilege is not available
176
-     * and return true otherwise.
177
-     *
178
-     * @param string $uri
179
-     * @param array|string $privileges
180
-     * @param int $recursion
181
-     * @param bool $throwExceptions if set to false, this method won't throw exceptions.
182
-     * @throws Sabre\DAVACL\Exception\NeedPrivileges
183
-     * @return bool
184
-     */
185
-    public function checkPrivileges($uri, $privileges, $recursion = self::R_PARENT, $throwExceptions = true) {
186
-
187
-        if (!is_array($privileges)) $privileges = [$privileges];
188
-
189
-        $acl = $this->getCurrentUserPrivilegeSet($uri);
190
-
191
-        if (is_null($acl)) {
192
-            if ($this->allowAccessToNodesWithoutACL) {
193
-                return true;
194
-            } else {
195
-                if ($throwExceptions)
196
-                    throw new Exception\NeedPrivileges($uri, $privileges);
197
-                else
198
-                    return false;
199
-
200
-            }
201
-        }
202
-
203
-        $failed = [];
204
-        foreach ($privileges as $priv) {
205
-
206
-            if (!in_array($priv, $acl)) {
207
-                $failed[] = $priv;
208
-            }
209
-
210
-        }
211
-
212
-        if ($failed) {
213
-            if ($throwExceptions)
214
-                throw new Exception\NeedPrivileges($uri, $failed);
215
-            else
216
-                return false;
217
-        }
218
-        return true;
28
+	/**
29
+	 * Recursion constants
30
+	 *
31
+	 * This only checks the base node
32
+	 */
33
+	const R_PARENT = 1;
34
+
35
+	/**
36
+	 * Recursion constants
37
+	 *
38
+	 * This checks every node in the tree
39
+	 */
40
+	const R_RECURSIVE = 2;
41
+
42
+	/**
43
+	 * Recursion constants
44
+	 *
45
+	 * This checks every parentnode in the tree, but not leaf-nodes.
46
+	 */
47
+	const R_RECURSIVEPARENTS = 3;
48
+
49
+	/**
50
+	 * Reference to server object.
51
+	 *
52
+	 * @var Sabre\DAV\Server
53
+	 */
54
+	protected $server;
55
+
56
+	/**
57
+	 * List of urls containing principal collections.
58
+	 * Modify this if your principals are located elsewhere.
59
+	 *
60
+	 * @var array
61
+	 */
62
+	public $principalCollectionSet = [
63
+		'principals',
64
+	];
65
+
66
+	/**
67
+	 * By default ACL is only enforced for nodes that have ACL support (the
68
+	 * ones that implement IACL). For any other node, access is
69
+	 * always granted.
70
+	 *
71
+	 * To override this behaviour you can turn this setting off. This is useful
72
+	 * if you plan to fully support ACL in the entire tree.
73
+	 *
74
+	 * @var bool
75
+	 */
76
+	public $allowAccessToNodesWithoutACL = true;
77
+
78
+	/**
79
+	 * By default nodes that are inaccessible by the user, can still be seen
80
+	 * in directory listings (PROPFIND on parent with Depth: 1)
81
+	 *
82
+	 * In certain cases it's desirable to hide inaccessible nodes. Setting this
83
+	 * to true will cause these nodes to be hidden from directory listings.
84
+	 *
85
+	 * @var bool
86
+	 */
87
+	public $hideNodesFromListings = false;
88
+
89
+	/**
90
+	 * This list of properties are the properties a client can search on using
91
+	 * the {DAV:}principal-property-search report.
92
+	 *
93
+	 * The keys are the property names, values are descriptions.
94
+	 *
95
+	 * @var array
96
+	 */
97
+	public $principalSearchPropertySet = [
98
+		'{DAV:}displayname'                     => 'Display name',
99
+		'{http://sabredav.org/ns}email-address' => 'Email address',
100
+	];
101
+
102
+	/**
103
+	 * Any principal uri's added here, will automatically be added to the list
104
+	 * of ACL's. They will effectively receive {DAV:}all privileges, as a
105
+	 * protected privilege.
106
+	 *
107
+	 * @var array
108
+	 */
109
+	public $adminPrincipals = [];
110
+
111
+	/**
112
+	 * Returns a list of features added by this plugin.
113
+	 *
114
+	 * This list is used in the response of a HTTP OPTIONS request.
115
+	 *
116
+	 * @return array
117
+	 */
118
+	public function getFeatures() {
119
+
120
+		return ['access-control', 'calendarserver-principal-property-search'];
121
+
122
+	}
123
+
124
+	/**
125
+	 * Returns a list of available methods for a given url
126
+	 *
127
+	 * @param string $uri
128
+	 * @return array
129
+	 */
130
+	public function getMethods($uri) {
131
+
132
+		return ['ACL'];
133
+
134
+	}
135
+
136
+	/**
137
+	 * Returns a plugin name.
138
+	 *
139
+	 * Using this name other plugins will be able to access other plugins
140
+	 * using Sabre\DAV\Server::getPlugin
141
+	 *
142
+	 * @return string
143
+	 */
144
+	public function getPluginName() {
145
+
146
+		return 'acl';
147
+
148
+	}
149
+
150
+	/**
151
+	 * Returns a list of reports this plugin supports.
152
+	 *
153
+	 * This will be used in the {DAV:}supported-report-set property.
154
+	 * Note that you still need to subscribe to the 'report' event to actually
155
+	 * implement them
156
+	 *
157
+	 * @param string $uri
158
+	 * @return array
159
+	 */
160
+	public function getSupportedReportSet($uri) {
161
+
162
+		return [
163
+			'{DAV:}expand-property',
164
+			'{DAV:}principal-property-search',
165
+			'{DAV:}principal-search-property-set',
166
+		];
167
+
168
+	}
169
+
170
+
171
+	/**
172
+	 * Checks if the current user has the specified privilege(s).
173
+	 *
174
+	 * You can specify a single privilege, or a list of privileges.
175
+	 * This method will throw an exception if the privilege is not available
176
+	 * and return true otherwise.
177
+	 *
178
+	 * @param string $uri
179
+	 * @param array|string $privileges
180
+	 * @param int $recursion
181
+	 * @param bool $throwExceptions if set to false, this method won't throw exceptions.
182
+	 * @throws Sabre\DAVACL\Exception\NeedPrivileges
183
+	 * @return bool
184
+	 */
185
+	public function checkPrivileges($uri, $privileges, $recursion = self::R_PARENT, $throwExceptions = true) {
186
+
187
+		if (!is_array($privileges)) $privileges = [$privileges];
188
+
189
+		$acl = $this->getCurrentUserPrivilegeSet($uri);
190
+
191
+		if (is_null($acl)) {
192
+			if ($this->allowAccessToNodesWithoutACL) {
193
+				return true;
194
+			} else {
195
+				if ($throwExceptions)
196
+					throw new Exception\NeedPrivileges($uri, $privileges);
197
+				else
198
+					return false;
199
+
200
+			}
201
+		}
202
+
203
+		$failed = [];
204
+		foreach ($privileges as $priv) {
205
+
206
+			if (!in_array($priv, $acl)) {
207
+				$failed[] = $priv;
208
+			}
209
+
210
+		}
211
+
212
+		if ($failed) {
213
+			if ($throwExceptions)
214
+				throw new Exception\NeedPrivileges($uri, $failed);
215
+			else
216
+				return false;
217
+		}
218
+		return true;
219 219
 
220
-    }
221
-
222
-    /**
223
-     * Returns the standard users' principal.
224
-     *
225
-     * This is one authorative principal url for the current user.
226
-     * This method will return null if the user wasn't logged in.
227
-     *
228
-     * @return string|null
229
-     */
230
-    public function getCurrentUserPrincipal() {
231
-
232
-        $authPlugin = $this->server->getPlugin('auth');
233
-        if (is_null($authPlugin)) return null;
234
-        /** @var $authPlugin Sabre\DAV\Auth\Plugin */
235
-
236
-        return $authPlugin->getCurrentPrincipal();
237
-
238
-    }
239
-
240
-
241
-    /**
242
-     * Returns a list of principals that's associated to the current
243
-     * user, either directly or through group membership.
244
-     *
245
-     * @return array
246
-     */
247
-    public function getCurrentUserPrincipals() {
248
-
249
-        $currentUser = $this->getCurrentUserPrincipal();
250
-
251
-        if (is_null($currentUser)) return [];
252
-
253
-        return array_merge(
254
-            [$currentUser],
255
-            $this->getPrincipalMembership($currentUser)
256
-        );
257
-
258
-    }
259
-
260
-    /**
261
-     * This array holds a cache for all the principals that are associated with
262
-     * a single principal.
263
-     *
264
-     * @var array
265
-     */
266
-    protected $principalMembershipCache = [];
267
-
268
-
269
-    /**
270
-     * Returns all the principal groups the specified principal is a member of.
271
-     *
272
-     * @param string $principal
273
-     * @return array
274
-     */
275
-    public function getPrincipalMembership($mainPrincipal) {
276
-
277
-        // First check our cache
278
-        if (isset($this->principalMembershipCache[$mainPrincipal])) {
279
-            return $this->principalMembershipCache[$mainPrincipal];
280
-        }
281
-
282
-        $check = [$mainPrincipal];
283
-        $principals = [];
284
-
285
-        while (count($check)) {
286
-
287
-            $principal = array_shift($check);
288
-
289
-            $node = $this->server->tree->getNodeForPath($principal);
290
-            if ($node instanceof IPrincipal) {
291
-                foreach ($node->getGroupMembership() as $groupMember) {
292
-
293
-                    if (!in_array($groupMember, $principals)) {
294
-
295
-                        $check[] = $groupMember;
296
-                        $principals[] = $groupMember;
297
-
298
-                    }
299
-
300
-                }
301
-
302
-            }
303
-
304
-        }
305
-
306
-        // Store the result in the cache
307
-        $this->principalMembershipCache[$mainPrincipal] = $principals;
308
-
309
-        return $principals;
310
-
311
-    }
312
-
313
-    /**
314
-     * Returns the supported privilege structure for this ACL plugin.
315
-     *
316
-     * See RFC3744 for more details. Currently we default on a simple,
317
-     * standard structure.
318
-     *
319
-     * You can either get the list of privileges by a uri (path) or by
320
-     * specifying a Node.
321
-     *
322
-     * @param string|INode $node
323
-     * @return array
324
-     */
325
-    public function getSupportedPrivilegeSet($node) {
326
-
327
-        if (is_string($node)) {
328
-            $node = $this->server->tree->getNodeForPath($node);
329
-        }
330
-
331
-        if ($node instanceof IACL) {
332
-            $result = $node->getSupportedPrivilegeSet();
333
-
334
-            if ($result)
335
-                return $result;
336
-        }
337
-
338
-        return self::getDefaultSupportedPrivilegeSet();
339
-
340
-    }
341
-
342
-    /**
343
-     * Returns a fairly standard set of privileges, which may be useful for
344
-     * other systems to use as a basis.
345
-     *
346
-     * @return array
347
-     */
348
-    static function getDefaultSupportedPrivilegeSet() {
349
-
350
-        return [
351
-            'privilege'  => '{DAV:}all',
352
-            'abstract'   => true,
353
-            'aggregates' => [
354
-                [
355
-                    'privilege'  => '{DAV:}read',
356
-                    'aggregates' => [
357
-                        [
358
-                            'privilege' => '{DAV:}read-acl',
359
-                            'abstract'  => false,
360
-                        ],
361
-                        [
362
-                            'privilege' => '{DAV:}read-current-user-privilege-set',
363
-                            'abstract'  => false,
364
-                        ],
365
-                    ],
366
-                ], // {DAV:}read
367
-                [
368
-                    'privilege'  => '{DAV:}write',
369
-                    'aggregates' => [
370
-                        [
371
-                            'privilege' => '{DAV:}write-acl',
372
-                            'abstract'  => false,
373
-                        ],
374
-                        [
375
-                            'privilege' => '{DAV:}write-properties',
376
-                            'abstract'  => false,
377
-                        ],
378
-                        [
379
-                            'privilege' => '{DAV:}write-content',
380
-                            'abstract'  => false,
381
-                        ],
382
-                        [
383
-                            'privilege' => '{DAV:}bind',
384
-                            'abstract'  => false,
385
-                        ],
386
-                        [
387
-                            'privilege' => '{DAV:}unbind',
388
-                            'abstract'  => false,
389
-                        ],
390
-                        [
391
-                            'privilege' => '{DAV:}unlock',
392
-                            'abstract'  => false,
393
-                        ],
394
-                    ],
395
-                ], // {DAV:}write
396
-            ],
397
-        ]; // {DAV:}all
398
-
399
-    }
400
-
401
-    /**
402
-     * Returns the supported privilege set as a flat list
403
-     *
404
-     * This is much easier to parse.
405
-     *
406
-     * The returned list will be index by privilege name.
407
-     * The value is a struct containing the following properties:
408
-     *   - aggregates
409
-     *   - abstract
410
-     *   - concrete
411
-     *
412
-     * @param string|INode $node
413
-     * @return array
414
-     */
415
-    final function getFlatPrivilegeSet($node) {
416
-
417
-        $privs = $this->getSupportedPrivilegeSet($node);
418
-
419
-        $fpsTraverse = null;
420
-        $fpsTraverse = function($priv, $concrete, &$flat) use (&$fpsTraverse) {
421
-
422
-            $myPriv = [
423
-                'privilege'  => $priv['privilege'],
424
-                'abstract'   => isset($priv['abstract']) && $priv['abstract'],
425
-                'aggregates' => [],
426
-                'concrete'   => isset($priv['abstract']) && $priv['abstract'] ? $concrete : $priv['privilege'],
427
-            ];
428
-
429
-            if (isset($priv['aggregates'])) {
430
-
431
-                foreach ($priv['aggregates'] as $subPriv) {
432
-
433
-                    $myPriv['aggregates'][] = $subPriv['privilege'];
434
-
435
-                }
436
-
437
-            }
438
-
439
-            $flat[$priv['privilege']] = $myPriv;
440
-
441
-            if (isset($priv['aggregates'])) {
442
-
443
-                foreach ($priv['aggregates'] as $subPriv) {
444
-
445
-                    $fpsTraverse($subPriv, $myPriv['concrete'], $flat);
446
-
447
-                }
448
-
449
-            }
450
-
451
-        };
452
-
453
-        $flat = [];
454
-        $fpsTraverse($privs, null, $flat);
455
-
456
-        return $flat;
457
-
458
-    }
459
-
460
-    /**
461
-     * Returns the full ACL list.
462
-     *
463
-     * Either a uri or a INode may be passed.
464
-     *
465
-     * null will be returned if the node doesn't support ACLs.
466
-     *
467
-     * @param string|DAV\INode $node
468
-     * @return array
469
-     */
470
-    public function getACL($node) {
471
-
472
-        if (is_string($node)) {
473
-            $node = $this->server->tree->getNodeForPath($node);
474
-        }
475
-        if (!$node instanceof IACL) {
476
-            return null;
477
-        }
478
-        $acl = $node->getACL();
479
-        foreach ($this->adminPrincipals as $adminPrincipal) {
480
-            $acl[] = [
481
-                'principal' => $adminPrincipal,
482
-                'privilege' => '{DAV:}all',
483
-                'protected' => true,
484
-            ];
485
-        }
486
-        return $acl;
220
+	}
221
+
222
+	/**
223
+	 * Returns the standard users' principal.
224
+	 *
225
+	 * This is one authorative principal url for the current user.
226
+	 * This method will return null if the user wasn't logged in.
227
+	 *
228
+	 * @return string|null
229
+	 */
230
+	public function getCurrentUserPrincipal() {
231
+
232
+		$authPlugin = $this->server->getPlugin('auth');
233
+		if (is_null($authPlugin)) return null;
234
+		/** @var $authPlugin Sabre\DAV\Auth\Plugin */
235
+
236
+		return $authPlugin->getCurrentPrincipal();
237
+
238
+	}
239
+
240
+
241
+	/**
242
+	 * Returns a list of principals that's associated to the current
243
+	 * user, either directly or through group membership.
244
+	 *
245
+	 * @return array
246
+	 */
247
+	public function getCurrentUserPrincipals() {
248
+
249
+		$currentUser = $this->getCurrentUserPrincipal();
250
+
251
+		if (is_null($currentUser)) return [];
252
+
253
+		return array_merge(
254
+			[$currentUser],
255
+			$this->getPrincipalMembership($currentUser)
256
+		);
257
+
258
+	}
259
+
260
+	/**
261
+	 * This array holds a cache for all the principals that are associated with
262
+	 * a single principal.
263
+	 *
264
+	 * @var array
265
+	 */
266
+	protected $principalMembershipCache = [];
267
+
268
+
269
+	/**
270
+	 * Returns all the principal groups the specified principal is a member of.
271
+	 *
272
+	 * @param string $principal
273
+	 * @return array
274
+	 */
275
+	public function getPrincipalMembership($mainPrincipal) {
276
+
277
+		// First check our cache
278
+		if (isset($this->principalMembershipCache[$mainPrincipal])) {
279
+			return $this->principalMembershipCache[$mainPrincipal];
280
+		}
281
+
282
+		$check = [$mainPrincipal];
283
+		$principals = [];
284
+
285
+		while (count($check)) {
286
+
287
+			$principal = array_shift($check);
288
+
289
+			$node = $this->server->tree->getNodeForPath($principal);
290
+			if ($node instanceof IPrincipal) {
291
+				foreach ($node->getGroupMembership() as $groupMember) {
292
+
293
+					if (!in_array($groupMember, $principals)) {
294
+
295
+						$check[] = $groupMember;
296
+						$principals[] = $groupMember;
297
+
298
+					}
299
+
300
+				}
301
+
302
+			}
303
+
304
+		}
305
+
306
+		// Store the result in the cache
307
+		$this->principalMembershipCache[$mainPrincipal] = $principals;
308
+
309
+		return $principals;
310
+
311
+	}
312
+
313
+	/**
314
+	 * Returns the supported privilege structure for this ACL plugin.
315
+	 *
316
+	 * See RFC3744 for more details. Currently we default on a simple,
317
+	 * standard structure.
318
+	 *
319
+	 * You can either get the list of privileges by a uri (path) or by
320
+	 * specifying a Node.
321
+	 *
322
+	 * @param string|INode $node
323
+	 * @return array
324
+	 */
325
+	public function getSupportedPrivilegeSet($node) {
326
+
327
+		if (is_string($node)) {
328
+			$node = $this->server->tree->getNodeForPath($node);
329
+		}
330
+
331
+		if ($node instanceof IACL) {
332
+			$result = $node->getSupportedPrivilegeSet();
333
+
334
+			if ($result)
335
+				return $result;
336
+		}
337
+
338
+		return self::getDefaultSupportedPrivilegeSet();
339
+
340
+	}
341
+
342
+	/**
343
+	 * Returns a fairly standard set of privileges, which may be useful for
344
+	 * other systems to use as a basis.
345
+	 *
346
+	 * @return array
347
+	 */
348
+	static function getDefaultSupportedPrivilegeSet() {
349
+
350
+		return [
351
+			'privilege'  => '{DAV:}all',
352
+			'abstract'   => true,
353
+			'aggregates' => [
354
+				[
355
+					'privilege'  => '{DAV:}read',
356
+					'aggregates' => [
357
+						[
358
+							'privilege' => '{DAV:}read-acl',
359
+							'abstract'  => false,
360
+						],
361
+						[
362
+							'privilege' => '{DAV:}read-current-user-privilege-set',
363
+							'abstract'  => false,
364
+						],
365
+					],
366
+				], // {DAV:}read
367
+				[
368
+					'privilege'  => '{DAV:}write',
369
+					'aggregates' => [
370
+						[
371
+							'privilege' => '{DAV:}write-acl',
372
+							'abstract'  => false,
373
+						],
374
+						[
375
+							'privilege' => '{DAV:}write-properties',
376
+							'abstract'  => false,
377
+						],
378
+						[
379
+							'privilege' => '{DAV:}write-content',
380
+							'abstract'  => false,
381
+						],
382
+						[
383
+							'privilege' => '{DAV:}bind',
384
+							'abstract'  => false,
385
+						],
386
+						[
387
+							'privilege' => '{DAV:}unbind',
388
+							'abstract'  => false,
389
+						],
390
+						[
391
+							'privilege' => '{DAV:}unlock',
392
+							'abstract'  => false,
393
+						],
394
+					],
395
+				], // {DAV:}write
396
+			],
397
+		]; // {DAV:}all
398
+
399
+	}
400
+
401
+	/**
402
+	 * Returns the supported privilege set as a flat list
403
+	 *
404
+	 * This is much easier to parse.
405
+	 *
406
+	 * The returned list will be index by privilege name.
407
+	 * The value is a struct containing the following properties:
408
+	 *   - aggregates
409
+	 *   - abstract
410
+	 *   - concrete
411
+	 *
412
+	 * @param string|INode $node
413
+	 * @return array
414
+	 */
415
+	final function getFlatPrivilegeSet($node) {
416
+
417
+		$privs = $this->getSupportedPrivilegeSet($node);
418
+
419
+		$fpsTraverse = null;
420
+		$fpsTraverse = function($priv, $concrete, &$flat) use (&$fpsTraverse) {
421
+
422
+			$myPriv = [
423
+				'privilege'  => $priv['privilege'],
424
+				'abstract'   => isset($priv['abstract']) && $priv['abstract'],
425
+				'aggregates' => [],
426
+				'concrete'   => isset($priv['abstract']) && $priv['abstract'] ? $concrete : $priv['privilege'],
427
+			];
428
+
429
+			if (isset($priv['aggregates'])) {
430
+
431
+				foreach ($priv['aggregates'] as $subPriv) {
432
+
433
+					$myPriv['aggregates'][] = $subPriv['privilege'];
434
+
435
+				}
436
+
437
+			}
438
+
439
+			$flat[$priv['privilege']] = $myPriv;
440
+
441
+			if (isset($priv['aggregates'])) {
442
+
443
+				foreach ($priv['aggregates'] as $subPriv) {
444
+
445
+					$fpsTraverse($subPriv, $myPriv['concrete'], $flat);
446
+
447
+				}
448
+
449
+			}
450
+
451
+		};
452
+
453
+		$flat = [];
454
+		$fpsTraverse($privs, null, $flat);
455
+
456
+		return $flat;
457
+
458
+	}
459
+
460
+	/**
461
+	 * Returns the full ACL list.
462
+	 *
463
+	 * Either a uri or a INode may be passed.
464
+	 *
465
+	 * null will be returned if the node doesn't support ACLs.
466
+	 *
467
+	 * @param string|DAV\INode $node
468
+	 * @return array
469
+	 */
470
+	public function getACL($node) {
471
+
472
+		if (is_string($node)) {
473
+			$node = $this->server->tree->getNodeForPath($node);
474
+		}
475
+		if (!$node instanceof IACL) {
476
+			return null;
477
+		}
478
+		$acl = $node->getACL();
479
+		foreach ($this->adminPrincipals as $adminPrincipal) {
480
+			$acl[] = [
481
+				'principal' => $adminPrincipal,
482
+				'privilege' => '{DAV:}all',
483
+				'protected' => true,
484
+			];
485
+		}
486
+		return $acl;
487 487
 
488
-    }
488
+	}
489 489
 
490
-    /**
491
-     * Returns a list of privileges the current user has
492
-     * on a particular node.
493
-     *
494
-     * Either a uri or a DAV\INode may be passed.
495
-     *
496
-     * null will be returned if the node doesn't support ACLs.
497
-     *
498
-     * @param string|DAV\INode $node
499
-     * @return array
500
-     */
501
-    public function getCurrentUserPrivilegeSet($node) {
490
+	/**
491
+	 * Returns a list of privileges the current user has
492
+	 * on a particular node.
493
+	 *
494
+	 * Either a uri or a DAV\INode may be passed.
495
+	 *
496
+	 * null will be returned if the node doesn't support ACLs.
497
+	 *
498
+	 * @param string|DAV\INode $node
499
+	 * @return array
500
+	 */
501
+	public function getCurrentUserPrivilegeSet($node) {
502 502
 
503
-        if (is_string($node)) {
504
-            $node = $this->server->tree->getNodeForPath($node);
505
-        }
503
+		if (is_string($node)) {
504
+			$node = $this->server->tree->getNodeForPath($node);
505
+		}
506 506
 
507
-        $acl = $this->getACL($node);
507
+		$acl = $this->getACL($node);
508 508
 
509
-        if (is_null($acl)) return null;
509
+		if (is_null($acl)) return null;
510 510
 
511
-        $principals = $this->getCurrentUserPrincipals();
511
+		$principals = $this->getCurrentUserPrincipals();
512 512
 
513
-        $collected = [];
513
+		$collected = [];
514 514
 
515
-        foreach ($acl as $ace) {
515
+		foreach ($acl as $ace) {
516 516
 
517
-            $principal = $ace['principal'];
517
+			$principal = $ace['principal'];
518 518
 
519
-            switch ($principal) {
519
+			switch ($principal) {
520 520
 
521
-                case '{DAV:}owner' :
522
-                    $owner = $node->getOwner();
523
-                    if ($owner && in_array($owner, $principals)) {
524
-                        $collected[] = $ace;
525
-                    }
526
-                    break;
521
+				case '{DAV:}owner' :
522
+					$owner = $node->getOwner();
523
+					if ($owner && in_array($owner, $principals)) {
524
+						$collected[] = $ace;
525
+					}
526
+					break;
527 527
 
528 528
 
529
-                // 'all' matches for every user
530
-                case '{DAV:}all' :
529
+				// 'all' matches for every user
530
+				case '{DAV:}all' :
531 531
 
532
-                // 'authenticated' matched for every user that's logged in.
533
-                // Since it's not possible to use ACL while not being logged
534
-                // in, this is also always true.
535
-                case '{DAV:}authenticated' :
536
-                    $collected[] = $ace;
537
-                    break;
538
-
539
-                // 'unauthenticated' can never occur either, so we simply
540
-                // ignore these.
541
-                case '{DAV:}unauthenticated' :
542
-                    break;
543
-
544
-                default :
545
-                    if (in_array($ace['principal'], $principals)) {
546
-                        $collected[] = $ace;
547
-                    }
548
-                    break;
549
-
550
-            }
551
-
552
-
553
-        }
554
-
555
-        // Now we deduct all aggregated privileges.
556
-        $flat = $this->getFlatPrivilegeSet($node);
557
-
558
-        $collected2 = [];
559
-        while (count($collected)) {
560
-
561
-            $current = array_pop($collected);
562
-            $collected2[] = $current['privilege'];
563
-
564
-            foreach ($flat[$current['privilege']]['aggregates'] as $subPriv) {
565
-                $collected2[] = $subPriv;
566
-                $collected[] = $flat[$subPriv];
567
-            }
568
-
569
-        }
570
-
571
-        return array_values(array_unique($collected2));
572
-
573
-    }
574
-
575
-
576
-    /**
577
-     * Returns a principal based on its uri.
578
-     *
579
-     * Returns null if the principal could not be found.
580
-     *
581
-     * @param string $uri
582
-     * @return null|string
583
-     */
584
-    public function getPrincipalByUri($uri) {
585
-
586
-        $result = null;
587
-        $collections = $this->principalCollectionSet;
588
-        foreach ($collections as $collection) {
589
-
590
-            $principalCollection = $this->server->tree->getNodeForPath($collection);
591
-            if (!$principalCollection instanceof IPrincipalCollection) {
592
-                // Not a principal collection, we're simply going to ignore
593
-                // this.
594
-                continue;
595
-            }
596
-
597
-            $result = $principalCollection->findByUri($uri);
598
-            if ($result) {
599
-                return $result;
600
-            }
601
-
602
-        }
603
-
604
-    }
605
-
606
-    /**
607
-     * Principal property search
608
-     *
609
-     * This method can search for principals matching certain values in
610
-     * properties.
611
-     *
612
-     * This method will return a list of properties for the matched properties.
613
-     *
614
-     * @param array $searchProperties    The properties to search on. This is a
615
-     *                                   key-value list. The keys are property
616
-     *                                   names, and the values the strings to
617
-     *                                   match them on.
618
-     * @param array $requestedProperties This is the list of properties to
619
-     *                                   return for every match.
620
-     * @param string $collectionUri      The principal collection to search on.
621
-     *                                   If this is ommitted, the standard
622
-     *                                   principal collection-set will be used.
623
-     * @param string $test               "allof" to use AND to search the
624
-     *                                   properties. 'anyof' for OR.
625
-     * @return array     This method returns an array structure similar to
626
-     *                  Sabre\DAV\Server::getPropertiesForPath. Returned
627
-     *                  properties are index by a HTTP status code.
628
-     */
629
-    public function principalSearch(array $searchProperties, array $requestedProperties, $collectionUri = null, $test = 'allof') {
630
-
631
-        if (!is_null($collectionUri)) {
632
-            $uris = [$collectionUri];
633
-        } else {
634
-            $uris = $this->principalCollectionSet;
635
-        }
636
-
637
-        $lookupResults = [];
638
-        foreach ($uris as $uri) {
639
-
640
-            $principalCollection = $this->server->tree->getNodeForPath($uri);
641
-            if (!$principalCollection instanceof IPrincipalCollection) {
642
-                // Not a principal collection, we're simply going to ignore
643
-                // this.
644
-                continue;
645
-            }
646
-
647
-            $results = $principalCollection->searchPrincipals($searchProperties, $test);
648
-            foreach ($results as $result) {
649
-                $lookupResults[] = rtrim($uri, '/') . '/' . $result;
650
-            }
651
-
652
-        }
653
-
654
-        $matches = [];
655
-
656
-        foreach ($lookupResults as $lookupResult) {
657
-
658
-            list($matches[]) = $this->server->getPropertiesForPath($lookupResult, $requestedProperties, 0);
659
-
660
-        }
661
-
662
-        return $matches;
663
-
664
-    }
665
-
666
-    /**
667
-     * Sets up the plugin
668
-     *
669
-     * This method is automatically called by the server class.
670
-     *
671
-     * @param DAV\Server $server
672
-     * @return void
673
-     */
674
-    public function initialize(DAV\Server $server) {
675
-
676
-        $this->server = $server;
677
-        $server->on('propFind',            [$this, 'propFind'], 20);
678
-        $server->on('beforeMethod',        [$this, 'beforeMethod'], 20);
679
-        $server->on('beforeBind',          [$this, 'beforeBind'], 20);
680
-        $server->on('beforeUnbind',        [$this, 'beforeUnbind'], 20);
681
-        $server->on('propPatch',           [$this, 'propPatch']);
682
-        $server->on('beforeUnlock',        [$this, 'beforeUnlock'], 20);
683
-        $server->on('report',              [$this, 'report']);
684
-        $server->on('method:ACL',          [$this, 'httpAcl']);
685
-        $server->on('onHTMLActionsPanel',  [$this, 'htmlActionsPanel']);
686
-
687
-        array_push($server->protectedProperties,
688
-            '{DAV:}alternate-URI-set',
689
-            '{DAV:}principal-URL',
690
-            '{DAV:}group-membership',
691
-            '{DAV:}principal-collection-set',
692
-            '{DAV:}current-user-principal',
693
-            '{DAV:}supported-privilege-set',
694
-            '{DAV:}current-user-privilege-set',
695
-            '{DAV:}acl',
696
-            '{DAV:}acl-restrictions',
697
-            '{DAV:}inherited-acl-set',
698
-            '{DAV:}owner',
699
-            '{DAV:}group'
700
-        );
701
-
702
-        // Automatically mapping nodes implementing IPrincipal to the
703
-        // {DAV:}principal resourcetype.
704
-        $server->resourceTypeMapping['Sabre\\DAVACL\\IPrincipal'] = '{DAV:}principal';
705
-
706
-        // Mapping the group-member-set property to the HrefList property
707
-        // class.
708
-        $server->xml->elementMap['{DAV:}group-member-set'] = 'Sabre\\DAV\\Xml\\Property\\Href';
709
-        $server->xml->elementMap['{DAV:}acl'] = 'Sabre\\DAVACL\\Xml\\Property\\Acl';
710
-        $server->xml->elementMap['{DAV:}expand-property'] = 'Sabre\\DAVACL\\Xml\\Request\\ExpandPropertyReport';
711
-        $server->xml->elementMap['{DAV:}principal-property-search'] = 'Sabre\\DAVACL\\Xml\\Request\\PrincipalPropertySearchReport';
712
-        $server->xml->elementMap['{DAV:}principal-search-property-set'] = 'Sabre\\DAVACL\\Xml\\Request\\PrincipalSearchPropertySetReport';
713
-
714
-    }
715
-
716
-    /* {{{ Event handlers */
717
-
718
-    /**
719
-     * Triggered before any method is handled
720
-     *
721
-     * @param RequestInterface $request
722
-     * @param ResponseInterface $response
723
-     * @return void
724
-     */
725
-    public function beforeMethod(RequestInterface $request, ResponseInterface $response) {
726
-
727
-        $method = $request->getMethod();
728
-        $path = $request->getPath();
729
-
730
-        $exists = $this->server->tree->nodeExists($path);
731
-
732
-        // If the node doesn't exists, none of these checks apply
733
-        if (!$exists) return;
734
-
735
-        switch ($method) {
736
-
737
-            case 'GET' :
738
-            case 'HEAD' :
739
-            case 'OPTIONS' :
740
-                // For these 3 we only need to know if the node is readable.
741
-                $this->checkPrivileges($path, '{DAV:}read');
742
-                break;
743
-
744
-            case 'PUT' :
745
-            case 'LOCK' :
746
-            case 'UNLOCK' :
747
-                // This method requires the write-content priv if the node
748
-                // already exists, and bind on the parent if the node is being
749
-                // created.
750
-                // The bind privilege is handled in the beforeBind event.
751
-                $this->checkPrivileges($path, '{DAV:}write-content');
752
-                break;
753
-
754
-
755
-            case 'PROPPATCH' :
756
-                $this->checkPrivileges($path, '{DAV:}write-properties');
757
-                break;
758
-
759
-            case 'ACL' :
760
-                $this->checkPrivileges($path, '{DAV:}write-acl');
761
-                break;
762
-
763
-            case 'COPY' :
764
-            case 'MOVE' :
765
-                // Copy requires read privileges on the entire source tree.
766
-                // If the target exists write-content normally needs to be
767
-                // checked, however, we're deleting the node beforehand and
768
-                // creating a new one after, so this is handled by the
769
-                // beforeUnbind event.
770
-                //
771
-                // The creation of the new node is handled by the beforeBind
772
-                // event.
773
-                //
774
-                // If MOVE is used beforeUnbind will also be used to check if
775
-                // the sourcenode can be deleted.
776
-                $this->checkPrivileges($path, '{DAV:}read', self::R_RECURSIVE);
777
-
778
-                break;
779
-
780
-        }
781
-
782
-    }
783
-
784
-    /**
785
-     * Triggered before a new node is created.
786
-     *
787
-     * This allows us to check permissions for any operation that creates a
788
-     * new node, such as PUT, MKCOL, MKCALENDAR, LOCK, COPY and MOVE.
789
-     *
790
-     * @param string $uri
791
-     * @return void
792
-     */
793
-    public function beforeBind($uri) {
794
-
795
-        list($parentUri) = Uri\split($uri);
796
-        $this->checkPrivileges($parentUri, '{DAV:}bind');
797
-
798
-    }
799
-
800
-    /**
801
-     * Triggered before a node is deleted
802
-     *
803
-     * This allows us to check permissions for any operation that will delete
804
-     * an existing node.
805
-     *
806
-     * @param string $uri
807
-     * @return void
808
-     */
809
-    public function beforeUnbind($uri) {
810
-
811
-        list($parentUri) = Uri\split($uri);
812
-        $this->checkPrivileges($parentUri, '{DAV:}unbind', self::R_RECURSIVEPARENTS);
813
-
814
-    }
815
-
816
-    /**
817
-     * Triggered before a node is unlocked.
818
-     *
819
-     * @param string $uri
820
-     * @param DAV\Locks\LockInfo $lock
821
-     * @return void
822
-     */
823
-    public function beforeUnlock($uri, DAV\Locks\LockInfo $lock) {
824
-
825
-
826
-    }
827
-
828
-    /**
829
-     * Triggered before properties are looked up in specific nodes.
830
-     *
831
-     * @param DAV\PropFind $propFind
832
-     * @param DAV\INode $node
833
-     * @param array $requestedProperties
834
-     * @param array $returnedProperties
835
-     * @return bool
836
-     */
837
-    public function propFind(DAV\PropFind $propFind, DAV\INode $node) {
838
-
839
-        $path = $propFind->getPath();
840
-
841
-        // Checking the read permission
842
-        if (!$this->checkPrivileges($path, '{DAV:}read', self::R_PARENT, false)) {
843
-            // User is not allowed to read properties
844
-
845
-            // Returning false causes the property-fetching system to pretend
846
-            // that the node does not exist, and will cause it to be hidden
847
-            // from listings such as PROPFIND or the browser plugin.
848
-            if ($this->hideNodesFromListings) {
849
-                return false;
850
-            }
851
-
852
-            // Otherwise we simply mark every property as 403.
853
-            foreach ($propFind->getRequestedProperties() as $requestedProperty) {
854
-                $propFind->set($requestedProperty, null, 403);
855
-            }
856
-
857
-            return;
858
-
859
-        }
860
-
861
-        /* Adding principal properties */
862
-        if ($node instanceof IPrincipal) {
863
-
864
-            $propFind->handle('{DAV:}alternate-URI-set', function() use ($node) {
865
-                return new DAV\Xml\Property\Href($node->getAlternateUriSet());
866
-            });
867
-            $propFind->handle('{DAV:}principal-URL', function() use ($node) {
868
-                return new DAV\Xml\Property\Href($node->getPrincipalUrl() . '/');
869
-            });
870
-            $propFind->handle('{DAV:}group-member-set', function() use ($node) {
871
-                $members = $node->getGroupMemberSet();
872
-                foreach ($members as $k => $member) {
873
-                    $members[$k] = rtrim($member, '/') . '/';
874
-                }
875
-                return new DAV\Xml\Property\Href($members);
876
-            });
877
-            $propFind->handle('{DAV:}group-membership', function() use ($node) {
878
-                $members = $node->getGroupMembership();
879
-                foreach ($members as $k => $member) {
880
-                    $members[$k] = rtrim($member, '/') . '/';
881
-                }
882
-                return new DAV\Xml\Property\Href($members);
883
-            });
884
-            $propFind->handle('{DAV:}displayname', [$node, 'getDisplayName']);
885
-
886
-        }
887
-
888
-        $propFind->handle('{DAV:}principal-collection-set', function() {
889
-
890
-            $val = $this->principalCollectionSet;
891
-            // Ensuring all collections end with a slash
892
-            foreach ($val as $k => $v) $val[$k] = $v . '/';
893
-            return new DAV\Xml\Property\Href($val);
894
-
895
-        });
896
-        $propFind->handle('{DAV:}current-user-principal', function() {
897
-            if ($url = $this->getCurrentUserPrincipal()) {
898
-                return new Xml\Property\Principal(Xml\Property\Principal::HREF, $url . '/');
899
-            } else {
900
-                return new Xml\Property\Principal(Xml\Property\Principal::UNAUTHENTICATED);
901
-            }
902
-        });
903
-        $propFind->handle('{DAV:}supported-privilege-set', function() use ($node) {
904
-            return new Xml\Property\SupportedPrivilegeSet($this->getSupportedPrivilegeSet($node));
905
-        });
906
-        $propFind->handle('{DAV:}current-user-privilege-set', function() use ($node, $propFind, $path) {
907
-            if (!$this->checkPrivileges($path, '{DAV:}read-current-user-privilege-set', self::R_PARENT, false)) {
908
-                $propFind->set('{DAV:}current-user-privilege-set', null, 403);
909
-            } else {
910
-                $val = $this->getCurrentUserPrivilegeSet($node);
911
-                if (!is_null($val)) {
912
-                    return new Xml\Property\CurrentUserPrivilegeSet($val);
913
-                }
914
-            }
915
-        });
916
-        $propFind->handle('{DAV:}acl', function() use ($node, $propFind, $path) {
917
-            /* The ACL property contains all the permissions */
918
-            if (!$this->checkPrivileges($path, '{DAV:}read-acl', self::R_PARENT, false)) {
919
-                $propFind->set('{DAV:}acl', null, 403);
920
-            } else {
921
-                $acl = $this->getACL($node);
922
-                if (!is_null($acl)) {
923
-                    return new Xml\Property\Acl($this->getACL($node));
924
-                }
925
-            }
926
-        });
927
-        $propFind->handle('{DAV:}acl-restrictions', function() {
928
-            return new Xml\Property\AclRestrictions();
929
-        });
930
-
931
-        /* Adding ACL properties */
932
-        if ($node instanceof IACL) {
933
-            $propFind->handle('{DAV:}owner', function() use ($node) {
934
-                return new DAV\Xml\Property\Href($node->getOwner() . '/');
935
-            });
936
-        }
937
-
938
-    }
939
-
940
-    /**
941
-     * This method intercepts PROPPATCH methods and make sure the
942
-     * group-member-set is updated correctly.
943
-     *
944
-     * @param string $path
945
-     * @param DAV\PropPatch $propPatch
946
-     * @return void
947
-     */
948
-    public function propPatch($path, DAV\PropPatch $propPatch) {
949
-
950
-        $propPatch->handle('{DAV:}group-member-set', function($value) use ($path) {
951
-            if (is_null($value)) {
952
-                $memberSet = [];
953
-            } elseif ($value instanceof DAV\Xml\Property\Href) {
954
-                $memberSet = array_map(
955
-                    [$this->server, 'calculateUri'],
956
-                    $value->getHrefs()
957
-                );
958
-            } else {
959
-                throw new DAV\Exception('The group-member-set property MUST be an instance of Sabre\DAV\Property\HrefList or null');
960
-            }
961
-            $node = $this->server->tree->getNodeForPath($path);
962
-            if (!($node instanceof IPrincipal)) {
963
-                // Fail
964
-                return false;
965
-            }
966
-
967
-            $node->setGroupMemberSet($memberSet);
968
-            // We must also clear our cache, just in case
969
-
970
-            $this->principalMembershipCache = [];
971
-
972
-            return true;
973
-        });
974
-
975
-    }
976
-
977
-    /**
978
-     * This method handles HTTP REPORT requests
979
-     *
980
-     * @param string $reportName
981
-     * @param mixed $report
982
-     * @param mixed $path
983
-     * @return bool
984
-     */
985
-    public function report($reportName, $report, $path) {
986
-
987
-        switch ($reportName) {
988
-
989
-            case '{DAV:}principal-property-search' :
990
-                $this->server->transactionType = 'report-principal-property-search';
991
-                $this->principalPropertySearchReport($report);
992
-                return false;
993
-            case '{DAV:}principal-search-property-set' :
994
-                $this->server->transactionType = 'report-principal-search-property-set';
995
-                $this->principalSearchPropertySetReport($report);
996
-                return false;
997
-            case '{DAV:}expand-property' :
998
-                $this->server->transactionType = 'report-expand-property';
999
-                $this->expandPropertyReport($report);
1000
-                return false;
1001
-
1002
-        }
1003
-
1004
-    }
1005
-
1006
-    /**
1007
-     * This method is responsible for handling the 'ACL' event.
1008
-     *
1009
-     * @param RequestInterface $request
1010
-     * @param ResponseInterface $response
1011
-     * @return bool
1012
-     */
1013
-    public function httpAcl(RequestInterface $request, ResponseInterface $response) {
1014
-
1015
-        $path = $request->getPath();
1016
-        $body = $request->getBodyAsString();
1017
-
1018
-        if (!$body) {
1019
-            throw new DAV\Exception\BadRequest('XML body expected in ACL request');
1020
-        }
1021
-
1022
-        $acl = $this->server->xml->expect('{DAV:}acl', $body);
1023
-        $newAcl = $acl->getPrivileges();
1024
-
1025
-        // Normalizing urls
1026
-        foreach ($newAcl as $k => $newAce) {
1027
-            $newAcl[$k]['principal'] = $this->server->calculateUri($newAce['principal']);
1028
-        }
1029
-        $node = $this->server->tree->getNodeForPath($path);
1030
-
1031
-        if (!$node instanceof IACL) {
1032
-            throw new DAV\Exception\MethodNotAllowed('This node does not support the ACL method');
1033
-        }
1034
-
1035
-        $oldAcl = $this->getACL($node);
1036
-
1037
-        $supportedPrivileges = $this->getFlatPrivilegeSet($node);
1038
-
1039
-        /* Checking if protected principals from the existing principal set are
532
+				// 'authenticated' matched for every user that's logged in.
533
+				// Since it's not possible to use ACL while not being logged
534
+				// in, this is also always true.
535
+				case '{DAV:}authenticated' :
536
+					$collected[] = $ace;
537
+					break;
538
+
539
+				// 'unauthenticated' can never occur either, so we simply
540
+				// ignore these.
541
+				case '{DAV:}unauthenticated' :
542
+					break;
543
+
544
+				default :
545
+					if (in_array($ace['principal'], $principals)) {
546
+						$collected[] = $ace;
547
+					}
548
+					break;
549
+
550
+			}
551
+
552
+
553
+		}
554
+
555
+		// Now we deduct all aggregated privileges.
556
+		$flat = $this->getFlatPrivilegeSet($node);
557
+
558
+		$collected2 = [];
559
+		while (count($collected)) {
560
+
561
+			$current = array_pop($collected);
562
+			$collected2[] = $current['privilege'];
563
+
564
+			foreach ($flat[$current['privilege']]['aggregates'] as $subPriv) {
565
+				$collected2[] = $subPriv;
566
+				$collected[] = $flat[$subPriv];
567
+			}
568
+
569
+		}
570
+
571
+		return array_values(array_unique($collected2));
572
+
573
+	}
574
+
575
+
576
+	/**
577
+	 * Returns a principal based on its uri.
578
+	 *
579
+	 * Returns null if the principal could not be found.
580
+	 *
581
+	 * @param string $uri
582
+	 * @return null|string
583
+	 */
584
+	public function getPrincipalByUri($uri) {
585
+
586
+		$result = null;
587
+		$collections = $this->principalCollectionSet;
588
+		foreach ($collections as $collection) {
589
+
590
+			$principalCollection = $this->server->tree->getNodeForPath($collection);
591
+			if (!$principalCollection instanceof IPrincipalCollection) {
592
+				// Not a principal collection, we're simply going to ignore
593
+				// this.
594
+				continue;
595
+			}
596
+
597
+			$result = $principalCollection->findByUri($uri);
598
+			if ($result) {
599
+				return $result;
600
+			}
601
+
602
+		}
603
+
604
+	}
605
+
606
+	/**
607
+	 * Principal property search
608
+	 *
609
+	 * This method can search for principals matching certain values in
610
+	 * properties.
611
+	 *
612
+	 * This method will return a list of properties for the matched properties.
613
+	 *
614
+	 * @param array $searchProperties    The properties to search on. This is a
615
+	 *                                   key-value list. The keys are property
616
+	 *                                   names, and the values the strings to
617
+	 *                                   match them on.
618
+	 * @param array $requestedProperties This is the list of properties to
619
+	 *                                   return for every match.
620
+	 * @param string $collectionUri      The principal collection to search on.
621
+	 *                                   If this is ommitted, the standard
622
+	 *                                   principal collection-set will be used.
623
+	 * @param string $test               "allof" to use AND to search the
624
+	 *                                   properties. 'anyof' for OR.
625
+	 * @return array     This method returns an array structure similar to
626
+	 *                  Sabre\DAV\Server::getPropertiesForPath. Returned
627
+	 *                  properties are index by a HTTP status code.
628
+	 */
629
+	public function principalSearch(array $searchProperties, array $requestedProperties, $collectionUri = null, $test = 'allof') {
630
+
631
+		if (!is_null($collectionUri)) {
632
+			$uris = [$collectionUri];
633
+		} else {
634
+			$uris = $this->principalCollectionSet;
635
+		}
636
+
637
+		$lookupResults = [];
638
+		foreach ($uris as $uri) {
639
+
640
+			$principalCollection = $this->server->tree->getNodeForPath($uri);
641
+			if (!$principalCollection instanceof IPrincipalCollection) {
642
+				// Not a principal collection, we're simply going to ignore
643
+				// this.
644
+				continue;
645
+			}
646
+
647
+			$results = $principalCollection->searchPrincipals($searchProperties, $test);
648
+			foreach ($results as $result) {
649
+				$lookupResults[] = rtrim($uri, '/') . '/' . $result;
650
+			}
651
+
652
+		}
653
+
654
+		$matches = [];
655
+
656
+		foreach ($lookupResults as $lookupResult) {
657
+
658
+			list($matches[]) = $this->server->getPropertiesForPath($lookupResult, $requestedProperties, 0);
659
+
660
+		}
661
+
662
+		return $matches;
663
+
664
+	}
665
+
666
+	/**
667
+	 * Sets up the plugin
668
+	 *
669
+	 * This method is automatically called by the server class.
670
+	 *
671
+	 * @param DAV\Server $server
672
+	 * @return void
673
+	 */
674
+	public function initialize(DAV\Server $server) {
675
+
676
+		$this->server = $server;
677
+		$server->on('propFind',            [$this, 'propFind'], 20);
678
+		$server->on('beforeMethod',        [$this, 'beforeMethod'], 20);
679
+		$server->on('beforeBind',          [$this, 'beforeBind'], 20);
680
+		$server->on('beforeUnbind',        [$this, 'beforeUnbind'], 20);
681
+		$server->on('propPatch',           [$this, 'propPatch']);
682
+		$server->on('beforeUnlock',        [$this, 'beforeUnlock'], 20);
683
+		$server->on('report',              [$this, 'report']);
684
+		$server->on('method:ACL',          [$this, 'httpAcl']);
685
+		$server->on('onHTMLActionsPanel',  [$this, 'htmlActionsPanel']);
686
+
687
+		array_push($server->protectedProperties,
688
+			'{DAV:}alternate-URI-set',
689
+			'{DAV:}principal-URL',
690
+			'{DAV:}group-membership',
691
+			'{DAV:}principal-collection-set',
692
+			'{DAV:}current-user-principal',
693
+			'{DAV:}supported-privilege-set',
694
+			'{DAV:}current-user-privilege-set',
695
+			'{DAV:}acl',
696
+			'{DAV:}acl-restrictions',
697
+			'{DAV:}inherited-acl-set',
698
+			'{DAV:}owner',
699
+			'{DAV:}group'
700
+		);
701
+
702
+		// Automatically mapping nodes implementing IPrincipal to the
703
+		// {DAV:}principal resourcetype.
704
+		$server->resourceTypeMapping['Sabre\\DAVACL\\IPrincipal'] = '{DAV:}principal';
705
+
706
+		// Mapping the group-member-set property to the HrefList property
707
+		// class.
708
+		$server->xml->elementMap['{DAV:}group-member-set'] = 'Sabre\\DAV\\Xml\\Property\\Href';
709
+		$server->xml->elementMap['{DAV:}acl'] = 'Sabre\\DAVACL\\Xml\\Property\\Acl';
710
+		$server->xml->elementMap['{DAV:}expand-property'] = 'Sabre\\DAVACL\\Xml\\Request\\ExpandPropertyReport';
711
+		$server->xml->elementMap['{DAV:}principal-property-search'] = 'Sabre\\DAVACL\\Xml\\Request\\PrincipalPropertySearchReport';
712
+		$server->xml->elementMap['{DAV:}principal-search-property-set'] = 'Sabre\\DAVACL\\Xml\\Request\\PrincipalSearchPropertySetReport';
713
+
714
+	}
715
+
716
+	/* {{{ Event handlers */
717
+
718
+	/**
719
+	 * Triggered before any method is handled
720
+	 *
721
+	 * @param RequestInterface $request
722
+	 * @param ResponseInterface $response
723
+	 * @return void
724
+	 */
725
+	public function beforeMethod(RequestInterface $request, ResponseInterface $response) {
726
+
727
+		$method = $request->getMethod();
728
+		$path = $request->getPath();
729
+
730
+		$exists = $this->server->tree->nodeExists($path);
731
+
732
+		// If the node doesn't exists, none of these checks apply
733
+		if (!$exists) return;
734
+
735
+		switch ($method) {
736
+
737
+			case 'GET' :
738
+			case 'HEAD' :
739
+			case 'OPTIONS' :
740
+				// For these 3 we only need to know if the node is readable.
741
+				$this->checkPrivileges($path, '{DAV:}read');
742
+				break;
743
+
744
+			case 'PUT' :
745
+			case 'LOCK' :
746
+			case 'UNLOCK' :
747
+				// This method requires the write-content priv if the node
748
+				// already exists, and bind on the parent if the node is being
749
+				// created.
750
+				// The bind privilege is handled in the beforeBind event.
751
+				$this->checkPrivileges($path, '{DAV:}write-content');
752
+				break;
753
+
754
+
755
+			case 'PROPPATCH' :
756
+				$this->checkPrivileges($path, '{DAV:}write-properties');
757
+				break;
758
+
759
+			case 'ACL' :
760
+				$this->checkPrivileges($path, '{DAV:}write-acl');
761
+				break;
762
+
763
+			case 'COPY' :
764
+			case 'MOVE' :
765
+				// Copy requires read privileges on the entire source tree.
766
+				// If the target exists write-content normally needs to be
767
+				// checked, however, we're deleting the node beforehand and
768
+				// creating a new one after, so this is handled by the
769
+				// beforeUnbind event.
770
+				//
771
+				// The creation of the new node is handled by the beforeBind
772
+				// event.
773
+				//
774
+				// If MOVE is used beforeUnbind will also be used to check if
775
+				// the sourcenode can be deleted.
776
+				$this->checkPrivileges($path, '{DAV:}read', self::R_RECURSIVE);
777
+
778
+				break;
779
+
780
+		}
781
+
782
+	}
783
+
784
+	/**
785
+	 * Triggered before a new node is created.
786
+	 *
787
+	 * This allows us to check permissions for any operation that creates a
788
+	 * new node, such as PUT, MKCOL, MKCALENDAR, LOCK, COPY and MOVE.
789
+	 *
790
+	 * @param string $uri
791
+	 * @return void
792
+	 */
793
+	public function beforeBind($uri) {
794
+
795
+		list($parentUri) = Uri\split($uri);
796
+		$this->checkPrivileges($parentUri, '{DAV:}bind');
797
+
798
+	}
799
+
800
+	/**
801
+	 * Triggered before a node is deleted
802
+	 *
803
+	 * This allows us to check permissions for any operation that will delete
804
+	 * an existing node.
805
+	 *
806
+	 * @param string $uri
807
+	 * @return void
808
+	 */
809
+	public function beforeUnbind($uri) {
810
+
811
+		list($parentUri) = Uri\split($uri);
812
+		$this->checkPrivileges($parentUri, '{DAV:}unbind', self::R_RECURSIVEPARENTS);
813
+
814
+	}
815
+
816
+	/**
817
+	 * Triggered before a node is unlocked.
818
+	 *
819
+	 * @param string $uri
820
+	 * @param DAV\Locks\LockInfo $lock
821
+	 * @return void
822
+	 */
823
+	public function beforeUnlock($uri, DAV\Locks\LockInfo $lock) {
824
+
825
+
826
+	}
827
+
828
+	/**
829
+	 * Triggered before properties are looked up in specific nodes.
830
+	 *
831
+	 * @param DAV\PropFind $propFind
832
+	 * @param DAV\INode $node
833
+	 * @param array $requestedProperties
834
+	 * @param array $returnedProperties
835
+	 * @return bool
836
+	 */
837
+	public function propFind(DAV\PropFind $propFind, DAV\INode $node) {
838
+
839
+		$path = $propFind->getPath();
840
+
841
+		// Checking the read permission
842
+		if (!$this->checkPrivileges($path, '{DAV:}read', self::R_PARENT, false)) {
843
+			// User is not allowed to read properties
844
+
845
+			// Returning false causes the property-fetching system to pretend
846
+			// that the node does not exist, and will cause it to be hidden
847
+			// from listings such as PROPFIND or the browser plugin.
848
+			if ($this->hideNodesFromListings) {
849
+				return false;
850
+			}
851
+
852
+			// Otherwise we simply mark every property as 403.
853
+			foreach ($propFind->getRequestedProperties() as $requestedProperty) {
854
+				$propFind->set($requestedProperty, null, 403);
855
+			}
856
+
857
+			return;
858
+
859
+		}
860
+
861
+		/* Adding principal properties */
862
+		if ($node instanceof IPrincipal) {
863
+
864
+			$propFind->handle('{DAV:}alternate-URI-set', function() use ($node) {
865
+				return new DAV\Xml\Property\Href($node->getAlternateUriSet());
866
+			});
867
+			$propFind->handle('{DAV:}principal-URL', function() use ($node) {
868
+				return new DAV\Xml\Property\Href($node->getPrincipalUrl() . '/');
869
+			});
870
+			$propFind->handle('{DAV:}group-member-set', function() use ($node) {
871
+				$members = $node->getGroupMemberSet();
872
+				foreach ($members as $k => $member) {
873
+					$members[$k] = rtrim($member, '/') . '/';
874
+				}
875
+				return new DAV\Xml\Property\Href($members);
876
+			});
877
+			$propFind->handle('{DAV:}group-membership', function() use ($node) {
878
+				$members = $node->getGroupMembership();
879
+				foreach ($members as $k => $member) {
880
+					$members[$k] = rtrim($member, '/') . '/';
881
+				}
882
+				return new DAV\Xml\Property\Href($members);
883
+			});
884
+			$propFind->handle('{DAV:}displayname', [$node, 'getDisplayName']);
885
+
886
+		}
887
+
888
+		$propFind->handle('{DAV:}principal-collection-set', function() {
889
+
890
+			$val = $this->principalCollectionSet;
891
+			// Ensuring all collections end with a slash
892
+			foreach ($val as $k => $v) $val[$k] = $v . '/';
893
+			return new DAV\Xml\Property\Href($val);
894
+
895
+		});
896
+		$propFind->handle('{DAV:}current-user-principal', function() {
897
+			if ($url = $this->getCurrentUserPrincipal()) {
898
+				return new Xml\Property\Principal(Xml\Property\Principal::HREF, $url . '/');
899
+			} else {
900
+				return new Xml\Property\Principal(Xml\Property\Principal::UNAUTHENTICATED);
901
+			}
902
+		});
903
+		$propFind->handle('{DAV:}supported-privilege-set', function() use ($node) {
904
+			return new Xml\Property\SupportedPrivilegeSet($this->getSupportedPrivilegeSet($node));
905
+		});
906
+		$propFind->handle('{DAV:}current-user-privilege-set', function() use ($node, $propFind, $path) {
907
+			if (!$this->checkPrivileges($path, '{DAV:}read-current-user-privilege-set', self::R_PARENT, false)) {
908
+				$propFind->set('{DAV:}current-user-privilege-set', null, 403);
909
+			} else {
910
+				$val = $this->getCurrentUserPrivilegeSet($node);
911
+				if (!is_null($val)) {
912
+					return new Xml\Property\CurrentUserPrivilegeSet($val);
913
+				}
914
+			}
915
+		});
916
+		$propFind->handle('{DAV:}acl', function() use ($node, $propFind, $path) {
917
+			/* The ACL property contains all the permissions */
918
+			if (!$this->checkPrivileges($path, '{DAV:}read-acl', self::R_PARENT, false)) {
919
+				$propFind->set('{DAV:}acl', null, 403);
920
+			} else {
921
+				$acl = $this->getACL($node);
922
+				if (!is_null($acl)) {
923
+					return new Xml\Property\Acl($this->getACL($node));
924
+				}
925
+			}
926
+		});
927
+		$propFind->handle('{DAV:}acl-restrictions', function() {
928
+			return new Xml\Property\AclRestrictions();
929
+		});
930
+
931
+		/* Adding ACL properties */
932
+		if ($node instanceof IACL) {
933
+			$propFind->handle('{DAV:}owner', function() use ($node) {
934
+				return new DAV\Xml\Property\Href($node->getOwner() . '/');
935
+			});
936
+		}
937
+
938
+	}
939
+
940
+	/**
941
+	 * This method intercepts PROPPATCH methods and make sure the
942
+	 * group-member-set is updated correctly.
943
+	 *
944
+	 * @param string $path
945
+	 * @param DAV\PropPatch $propPatch
946
+	 * @return void
947
+	 */
948
+	public function propPatch($path, DAV\PropPatch $propPatch) {
949
+
950
+		$propPatch->handle('{DAV:}group-member-set', function($value) use ($path) {
951
+			if (is_null($value)) {
952
+				$memberSet = [];
953
+			} elseif ($value instanceof DAV\Xml\Property\Href) {
954
+				$memberSet = array_map(
955
+					[$this->server, 'calculateUri'],
956
+					$value->getHrefs()
957
+				);
958
+			} else {
959
+				throw new DAV\Exception('The group-member-set property MUST be an instance of Sabre\DAV\Property\HrefList or null');
960
+			}
961
+			$node = $this->server->tree->getNodeForPath($path);
962
+			if (!($node instanceof IPrincipal)) {
963
+				// Fail
964
+				return false;
965
+			}
966
+
967
+			$node->setGroupMemberSet($memberSet);
968
+			// We must also clear our cache, just in case
969
+
970
+			$this->principalMembershipCache = [];
971
+
972
+			return true;
973
+		});
974
+
975
+	}
976
+
977
+	/**
978
+	 * This method handles HTTP REPORT requests
979
+	 *
980
+	 * @param string $reportName
981
+	 * @param mixed $report
982
+	 * @param mixed $path
983
+	 * @return bool
984
+	 */
985
+	public function report($reportName, $report, $path) {
986
+
987
+		switch ($reportName) {
988
+
989
+			case '{DAV:}principal-property-search' :
990
+				$this->server->transactionType = 'report-principal-property-search';
991
+				$this->principalPropertySearchReport($report);
992
+				return false;
993
+			case '{DAV:}principal-search-property-set' :
994
+				$this->server->transactionType = 'report-principal-search-property-set';
995
+				$this->principalSearchPropertySetReport($report);
996
+				return false;
997
+			case '{DAV:}expand-property' :
998
+				$this->server->transactionType = 'report-expand-property';
999
+				$this->expandPropertyReport($report);
1000
+				return false;
1001
+
1002
+		}
1003
+
1004
+	}
1005
+
1006
+	/**
1007
+	 * This method is responsible for handling the 'ACL' event.
1008
+	 *
1009
+	 * @param RequestInterface $request
1010
+	 * @param ResponseInterface $response
1011
+	 * @return bool
1012
+	 */
1013
+	public function httpAcl(RequestInterface $request, ResponseInterface $response) {
1014
+
1015
+		$path = $request->getPath();
1016
+		$body = $request->getBodyAsString();
1017
+
1018
+		if (!$body) {
1019
+			throw new DAV\Exception\BadRequest('XML body expected in ACL request');
1020
+		}
1021
+
1022
+		$acl = $this->server->xml->expect('{DAV:}acl', $body);
1023
+		$newAcl = $acl->getPrivileges();
1024
+
1025
+		// Normalizing urls
1026
+		foreach ($newAcl as $k => $newAce) {
1027
+			$newAcl[$k]['principal'] = $this->server->calculateUri($newAce['principal']);
1028
+		}
1029
+		$node = $this->server->tree->getNodeForPath($path);
1030
+
1031
+		if (!$node instanceof IACL) {
1032
+			throw new DAV\Exception\MethodNotAllowed('This node does not support the ACL method');
1033
+		}
1034
+
1035
+		$oldAcl = $this->getACL($node);
1036
+
1037
+		$supportedPrivileges = $this->getFlatPrivilegeSet($node);
1038
+
1039
+		/* Checking if protected principals from the existing principal set are
1040 1040
            not overwritten. */
1041
-        foreach ($oldAcl as $oldAce) {
1042
-
1043
-            if (!isset($oldAce['protected']) || !$oldAce['protected']) continue;
1044
-
1045
-            $found = false;
1046
-            foreach ($newAcl as $newAce) {
1047
-                if (
1048
-                    $newAce['privilege'] === $oldAce['privilege'] &&
1049
-                    $newAce['principal'] === $oldAce['principal'] &&
1050
-                    $newAce['protected']
1051
-                )
1052
-                $found = true;
1053
-            }
1054
-
1055
-            if (!$found)
1056
-                throw new Exception\AceConflict('This resource contained a protected {DAV:}ace, but this privilege did not occur in the ACL request');
1057
-
1058
-        }
1041
+		foreach ($oldAcl as $oldAce) {
1042
+
1043
+			if (!isset($oldAce['protected']) || !$oldAce['protected']) continue;
1044
+
1045
+			$found = false;
1046
+			foreach ($newAcl as $newAce) {
1047
+				if (
1048
+					$newAce['privilege'] === $oldAce['privilege'] &&
1049
+					$newAce['principal'] === $oldAce['principal'] &&
1050
+					$newAce['protected']
1051
+				)
1052
+				$found = true;
1053
+			}
1054
+
1055
+			if (!$found)
1056
+				throw new Exception\AceConflict('This resource contained a protected {DAV:}ace, but this privilege did not occur in the ACL request');
1057
+
1058
+		}
1059 1059
 
1060
-        foreach ($newAcl as $newAce) {
1061
-
1062
-            // Do we recognize the privilege
1063
-            if (!isset($supportedPrivileges[$newAce['privilege']])) {
1064
-                throw new Exception\NotSupportedPrivilege('The privilege you specified (' . $newAce['privilege'] . ') is not recognized by this server');
1065
-            }
1066
-
1067
-            if ($supportedPrivileges[$newAce['privilege']]['abstract']) {
1068
-                throw new Exception\NoAbstract('The privilege you specified (' . $newAce['privilege'] . ') is an abstract privilege');
1069
-            }
1070
-
1071
-            // Looking up the principal
1072
-            try {
1073
-                $principal = $this->server->tree->getNodeForPath($newAce['principal']);
1074
-            } catch (DAV\Exception\NotFound $e) {
1075
-                throw new Exception\NotRecognizedPrincipal('The specified principal (' . $newAce['principal'] . ') does not exist');
1076
-            }
1077
-            if (!($principal instanceof IPrincipal)) {
1078
-                throw new Exception\NotRecognizedPrincipal('The specified uri (' . $newAce['principal'] . ') is not a principal');
1079
-            }
1060
+		foreach ($newAcl as $newAce) {
1061
+
1062
+			// Do we recognize the privilege
1063
+			if (!isset($supportedPrivileges[$newAce['privilege']])) {
1064
+				throw new Exception\NotSupportedPrivilege('The privilege you specified (' . $newAce['privilege'] . ') is not recognized by this server');
1065
+			}
1066
+
1067
+			if ($supportedPrivileges[$newAce['privilege']]['abstract']) {
1068
+				throw new Exception\NoAbstract('The privilege you specified (' . $newAce['privilege'] . ') is an abstract privilege');
1069
+			}
1070
+
1071
+			// Looking up the principal
1072
+			try {
1073
+				$principal = $this->server->tree->getNodeForPath($newAce['principal']);
1074
+			} catch (DAV\Exception\NotFound $e) {
1075
+				throw new Exception\NotRecognizedPrincipal('The specified principal (' . $newAce['principal'] . ') does not exist');
1076
+			}
1077
+			if (!($principal instanceof IPrincipal)) {
1078
+				throw new Exception\NotRecognizedPrincipal('The specified uri (' . $newAce['principal'] . ') is not a principal');
1079
+			}
1080 1080
 
1081
-        }
1082
-        $node->setACL($newAcl);
1081
+		}
1082
+		$node->setACL($newAcl);
1083 1083
 
1084
-        $response->setStatus(200);
1085
-
1086
-        // Breaking the event chain, because we handled this method.
1087
-        return false;
1088
-
1089
-    }
1090
-
1091
-    /* }}} */
1092
-
1093
-    /* Reports {{{ */
1094
-
1095
-    /**
1096
-     * The expand-property report is defined in RFC3253 section 3-8.
1097
-     *
1098
-     * This report is very similar to a standard PROPFIND. The difference is
1099
-     * that it has the additional ability to look at properties containing a
1100
-     * {DAV:}href element, follow that property and grab additional elements
1101
-     * there.
1102
-     *
1103
-     * Other rfc's, such as ACL rely on this report, so it made sense to put
1104
-     * it in this plugin.
1105
-     *
1106
-     * @param Xml\Request\ExpandPropertyReport $report
1107
-     * @return void
1108
-     */
1109
-    protected function expandPropertyReport($report) {
1084
+		$response->setStatus(200);
1085
+
1086
+		// Breaking the event chain, because we handled this method.
1087
+		return false;
1088
+
1089
+	}
1090
+
1091
+	/* }}} */
1092
+
1093
+	/* Reports {{{ */
1094
+
1095
+	/**
1096
+	 * The expand-property report is defined in RFC3253 section 3-8.
1097
+	 *
1098
+	 * This report is very similar to a standard PROPFIND. The difference is
1099
+	 * that it has the additional ability to look at properties containing a
1100
+	 * {DAV:}href element, follow that property and grab additional elements
1101
+	 * there.
1102
+	 *
1103
+	 * Other rfc's, such as ACL rely on this report, so it made sense to put
1104
+	 * it in this plugin.
1105
+	 *
1106
+	 * @param Xml\Request\ExpandPropertyReport $report
1107
+	 * @return void
1108
+	 */
1109
+	protected function expandPropertyReport($report) {
1110 1110
 
1111
-        $depth = $this->server->getHTTPDepth(0);
1112
-        $requestUri = $this->server->getRequestUri();
1111
+		$depth = $this->server->getHTTPDepth(0);
1112
+		$requestUri = $this->server->getRequestUri();
1113 1113
 
1114
-        $result = $this->expandProperties($requestUri, $report->properties, $depth);
1114
+		$result = $this->expandProperties($requestUri, $report->properties, $depth);
1115 1115
 
1116
-        $xml = $this->server->xml->write(
1117
-            '{DAV:}multistatus',
1118
-            new DAV\Xml\Response\MultiStatus($result),
1119
-            $this->server->getBaseUri()
1120
-        );
1121
-        $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8');
1122
-        $this->server->httpResponse->setStatus(207);
1123
-        $this->server->httpResponse->setBody($xml);
1116
+		$xml = $this->server->xml->write(
1117
+			'{DAV:}multistatus',
1118
+			new DAV\Xml\Response\MultiStatus($result),
1119
+			$this->server->getBaseUri()
1120
+		);
1121
+		$this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8');
1122
+		$this->server->httpResponse->setStatus(207);
1123
+		$this->server->httpResponse->setBody($xml);
1124 1124
 
1125
-    }
1125
+	}
1126 1126
 
1127
-    /**
1128
-     * This method expands all the properties and returns
1129
-     * a list with property values
1130
-     *
1131
-     * @param array $path
1132
-     * @param array $requestedProperties the list of required properties
1133
-     * @param int $depth
1134
-     * @return array
1135
-     */
1136
-    protected function expandProperties($path, array $requestedProperties, $depth) {
1127
+	/**
1128
+	 * This method expands all the properties and returns
1129
+	 * a list with property values
1130
+	 *
1131
+	 * @param array $path
1132
+	 * @param array $requestedProperties the list of required properties
1133
+	 * @param int $depth
1134
+	 * @return array
1135
+	 */
1136
+	protected function expandProperties($path, array $requestedProperties, $depth) {
1137 1137
 
1138
-        $foundProperties = $this->server->getPropertiesForPath($path, array_keys($requestedProperties), $depth);
1138
+		$foundProperties = $this->server->getPropertiesForPath($path, array_keys($requestedProperties), $depth);
1139 1139
 
1140
-        $result = [];
1140
+		$result = [];
1141 1141
 
1142
-        foreach ($foundProperties as $node) {
1143
-
1144
-            foreach ($requestedProperties as $propertyName => $childRequestedProperties) {
1145
-
1146
-                // We're only traversing if sub-properties were requested
1147
-                if (count($childRequestedProperties) === 0) continue;
1148
-
1149
-                // We only have to do the expansion if the property was found
1150
-                // and it contains an href element.
1151
-                if (!array_key_exists($propertyName, $node[200])) continue;
1152
-
1153
-                if (!$node[200][$propertyName] instanceof DAV\Xml\Property\Href) {
1154
-                    continue;
1155
-                }
1156
-
1157
-                $childHrefs = $node[200][$propertyName]->getHrefs();
1158
-                $childProps = [];
1159
-
1160
-                foreach ($childHrefs as $href) {
1161
-                    // Gathering the result of the children
1162
-                    $childProps[] = [
1163
-                        'name'  => '{DAV:}response',
1164
-                        'value' => $this->expandProperties($href, $childRequestedProperties, 0)[0]
1165
-                    ];
1166
-                }
1167
-
1168
-                // Replacing the property with its expannded form.
1169
-                $node[200][$propertyName] = $childProps;
1170
-
1171
-            }
1172
-            $result[] = new DAV\Xml\Element\Response($node['href'], $node);
1173
-
1174
-        }
1175
-
1176
-        return $result;
1177
-
1178
-    }
1179
-
1180
-    /**
1181
-     * principalSearchPropertySetReport
1182
-     *
1183
-     * This method responsible for handing the
1184
-     * {DAV:}principal-search-property-set report. This report returns a list
1185
-     * of properties the client may search on, using the
1186
-     * {DAV:}principal-property-search report.
1187
-     *
1188
-     * @param Xml\Request\PrincipalSearchPropertySetReport $report
1189
-     * @return void
1190
-     */
1191
-    protected function principalSearchPropertySetReport($report) {
1192
-
1193
-        $httpDepth = $this->server->getHTTPDepth(0);
1194
-        if ($httpDepth !== 0) {
1195
-            throw new DAV\Exception\BadRequest('This report is only defined when Depth: 0');
1196
-        }
1197
-
1198
-        $writer = $this->server->xml->getWriter();
1199
-        $writer->openMemory();
1200
-        $writer->startDocument();
1201
-
1202
-        $writer->startElement('{DAV:}principal-search-property-set');
1203
-
1204
-        foreach ($this->principalSearchPropertySet as $propertyName => $description) {
1205
-
1206
-            $writer->startElement('{DAV:}principal-search-property');
1207
-            $writer->startElement('{DAV:}prop');
1208
-
1209
-            $writer->writeElement($propertyName);
1210
-
1211
-            $writer->endElement(); // prop
1212
-
1213
-            if ($description) {
1214
-                $writer->write([[
1215
-                    'name'       => '{DAV:}description',
1216
-                    'value'      => $description,
1217
-                    'attributes' => ['xml:lang' => 'en']
1218
-                ]]);
1219
-            }
1220
-
1221
-            $writer->endElement(); // principal-search-property
1222
-
1223
-
1224
-        }
1225
-
1226
-        $writer->endElement(); // principal-search-property-set
1227
-
1228
-        $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8');
1229
-        $this->server->httpResponse->setStatus(200);
1230
-        $this->server->httpResponse->setBody($writer->outputMemory());
1231
-
1232
-    }
1142
+		foreach ($foundProperties as $node) {
1143
+
1144
+			foreach ($requestedProperties as $propertyName => $childRequestedProperties) {
1145
+
1146
+				// We're only traversing if sub-properties were requested
1147
+				if (count($childRequestedProperties) === 0) continue;
1148
+
1149
+				// We only have to do the expansion if the property was found
1150
+				// and it contains an href element.
1151
+				if (!array_key_exists($propertyName, $node[200])) continue;
1152
+
1153
+				if (!$node[200][$propertyName] instanceof DAV\Xml\Property\Href) {
1154
+					continue;
1155
+				}
1156
+
1157
+				$childHrefs = $node[200][$propertyName]->getHrefs();
1158
+				$childProps = [];
1159
+
1160
+				foreach ($childHrefs as $href) {
1161
+					// Gathering the result of the children
1162
+					$childProps[] = [
1163
+						'name'  => '{DAV:}response',
1164
+						'value' => $this->expandProperties($href, $childRequestedProperties, 0)[0]
1165
+					];
1166
+				}
1167
+
1168
+				// Replacing the property with its expannded form.
1169
+				$node[200][$propertyName] = $childProps;
1170
+
1171
+			}
1172
+			$result[] = new DAV\Xml\Element\Response($node['href'], $node);
1173
+
1174
+		}
1175
+
1176
+		return $result;
1177
+
1178
+	}
1179
+
1180
+	/**
1181
+	 * principalSearchPropertySetReport
1182
+	 *
1183
+	 * This method responsible for handing the
1184
+	 * {DAV:}principal-search-property-set report. This report returns a list
1185
+	 * of properties the client may search on, using the
1186
+	 * {DAV:}principal-property-search report.
1187
+	 *
1188
+	 * @param Xml\Request\PrincipalSearchPropertySetReport $report
1189
+	 * @return void
1190
+	 */
1191
+	protected function principalSearchPropertySetReport($report) {
1192
+
1193
+		$httpDepth = $this->server->getHTTPDepth(0);
1194
+		if ($httpDepth !== 0) {
1195
+			throw new DAV\Exception\BadRequest('This report is only defined when Depth: 0');
1196
+		}
1197
+
1198
+		$writer = $this->server->xml->getWriter();
1199
+		$writer->openMemory();
1200
+		$writer->startDocument();
1201
+
1202
+		$writer->startElement('{DAV:}principal-search-property-set');
1203
+
1204
+		foreach ($this->principalSearchPropertySet as $propertyName => $description) {
1205
+
1206
+			$writer->startElement('{DAV:}principal-search-property');
1207
+			$writer->startElement('{DAV:}prop');
1208
+
1209
+			$writer->writeElement($propertyName);
1210
+
1211
+			$writer->endElement(); // prop
1212
+
1213
+			if ($description) {
1214
+				$writer->write([[
1215
+					'name'       => '{DAV:}description',
1216
+					'value'      => $description,
1217
+					'attributes' => ['xml:lang' => 'en']
1218
+				]]);
1219
+			}
1220
+
1221
+			$writer->endElement(); // principal-search-property
1222
+
1223
+
1224
+		}
1225
+
1226
+		$writer->endElement(); // principal-search-property-set
1227
+
1228
+		$this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8');
1229
+		$this->server->httpResponse->setStatus(200);
1230
+		$this->server->httpResponse->setBody($writer->outputMemory());
1231
+
1232
+	}
1233 1233
 
1234
-    /**
1235
-     * principalPropertySearchReport
1236
-     *
1237
-     * This method is responsible for handing the
1238
-     * {DAV:}principal-property-search report. This report can be used for
1239
-     * clients to search for groups of principals, based on the value of one
1240
-     * or more properties.
1241
-     *
1242
-     * @param Xml\Request\PrincipalPropertySearchReport $report
1243
-     * @return void
1244
-     */
1245
-    protected function principalPropertySearchReport($report) {
1246
-
1247
-        $uri = null;
1248
-        if (!$report->applyToPrincipalCollectionSet) {
1249
-            $uri = $this->server->httpRequest->getPath();
1250
-        }
1251
-        if ($this->server->getHttpDepth('0') !== 0) {
1252
-            throw new BadRequest('Depth must be 0');
1253
-        }
1254
-        $result = $this->principalSearch(
1255
-            $report->searchProperties,
1256
-            $report->properties,
1257
-            $uri,
1258
-            $report->test
1259
-        );
1260
-
1261
-        $prefer = $this->server->getHTTPPrefer();
1262
-
1263
-        $this->server->httpResponse->setStatus(207);
1264
-        $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8');
1265
-        $this->server->httpResponse->setHeader('Vary', 'Brief,Prefer');
1266
-        $this->server->httpResponse->setBody($this->server->generateMultiStatus($result, $prefer['return'] === 'minimal'));
1267
-
1268
-    }
1269
-
1270
-    /* }}} */
1271
-
1272
-    /**
1273
-     * This method is used to generate HTML output for the
1274
-     * DAV\Browser\Plugin. This allows us to generate an interface users
1275
-     * can use to create new calendars.
1276
-     *
1277
-     * @param DAV\INode $node
1278
-     * @param string $output
1279
-     * @return bool
1280
-     */
1281
-    public function htmlActionsPanel(DAV\INode $node, &$output) {
1282
-
1283
-        if (!$node instanceof PrincipalCollection)
1284
-            return;
1285
-
1286
-        $output .= '<tr><td colspan="2"><form method="post" action="">
1234
+	/**
1235
+	 * principalPropertySearchReport
1236
+	 *
1237
+	 * This method is responsible for handing the
1238
+	 * {DAV:}principal-property-search report. This report can be used for
1239
+	 * clients to search for groups of principals, based on the value of one
1240
+	 * or more properties.
1241
+	 *
1242
+	 * @param Xml\Request\PrincipalPropertySearchReport $report
1243
+	 * @return void
1244
+	 */
1245
+	protected function principalPropertySearchReport($report) {
1246
+
1247
+		$uri = null;
1248
+		if (!$report->applyToPrincipalCollectionSet) {
1249
+			$uri = $this->server->httpRequest->getPath();
1250
+		}
1251
+		if ($this->server->getHttpDepth('0') !== 0) {
1252
+			throw new BadRequest('Depth must be 0');
1253
+		}
1254
+		$result = $this->principalSearch(
1255
+			$report->searchProperties,
1256
+			$report->properties,
1257
+			$uri,
1258
+			$report->test
1259
+		);
1260
+
1261
+		$prefer = $this->server->getHTTPPrefer();
1262
+
1263
+		$this->server->httpResponse->setStatus(207);
1264
+		$this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8');
1265
+		$this->server->httpResponse->setHeader('Vary', 'Brief,Prefer');
1266
+		$this->server->httpResponse->setBody($this->server->generateMultiStatus($result, $prefer['return'] === 'minimal'));
1267
+
1268
+	}
1269
+
1270
+	/* }}} */
1271
+
1272
+	/**
1273
+	 * This method is used to generate HTML output for the
1274
+	 * DAV\Browser\Plugin. This allows us to generate an interface users
1275
+	 * can use to create new calendars.
1276
+	 *
1277
+	 * @param DAV\INode $node
1278
+	 * @param string $output
1279
+	 * @return bool
1280
+	 */
1281
+	public function htmlActionsPanel(DAV\INode $node, &$output) {
1282
+
1283
+		if (!$node instanceof PrincipalCollection)
1284
+			return;
1285
+
1286
+		$output .= '<tr><td colspan="2"><form method="post" action="">
1287 1287
             <h3>Create new principal</h3>
1288 1288
             <input type="hidden" name="sabreAction" value="mkcol" />
1289 1289
             <input type="hidden" name="resourceType" value="{DAV:}principal" />
@@ -1294,28 +1294,28 @@  discard block
 block discarded – undo
1294 1294
             </form>
1295 1295
             </td></tr>';
1296 1296
 
1297
-        return false;
1298
-
1299
-    }
1300
-
1301
-    /**
1302
-     * Returns a bunch of meta-data about the plugin.
1303
-     *
1304
-     * Providing this information is optional, and is mainly displayed by the
1305
-     * Browser plugin.
1306
-     *
1307
-     * The description key in the returned array may contain html and will not
1308
-     * be sanitized.
1309
-     *
1310
-     * @return array
1311
-     */
1312
-    public function getPluginInfo() {
1313
-
1314
-        return [
1315
-            'name'        => $this->getPluginName(),
1316
-            'description' => 'Adds support for WebDAV ACL (rfc3744)',
1317
-            'link'        => 'http://sabre.io/dav/acl/',
1318
-        ];
1319
-
1320
-    }
1297
+		return false;
1298
+
1299
+	}
1300
+
1301
+	/**
1302
+	 * Returns a bunch of meta-data about the plugin.
1303
+	 *
1304
+	 * Providing this information is optional, and is mainly displayed by the
1305
+	 * Browser plugin.
1306
+	 *
1307
+	 * The description key in the returned array may contain html and will not
1308
+	 * be sanitized.
1309
+	 *
1310
+	 * @return array
1311
+	 */
1312
+	public function getPluginInfo() {
1313
+
1314
+		return [
1315
+			'name'        => $this->getPluginName(),
1316
+			'description' => 'Adds support for WebDAV ACL (rfc3744)',
1317
+			'link'        => 'http://sabre.io/dav/acl/',
1318
+		];
1319
+
1320
+	}
1321 1321
 }
Please login to merge, or discard this patch.
libraries/SabreDAV/DAVACL/Principal.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@
 block discarded – undo
39 39
     /**
40 40
      * Creates the principal object
41 41
      *
42
-     * @param IPrincipalBackend $principalBackend
42
+     * @param PrincipalBackend\BackendInterface $principalBackend
43 43
      * @param array $principalProperties
44 44
      */
45 45
     function __construct(PrincipalBackend\BackendInterface $principalBackend, array $principalProperties = []) {
Please login to merge, or discard this patch.
Indentation   +262 added lines, -262 removed lines patch added patch discarded remove patch
@@ -22,267 +22,267 @@
 block discarded – undo
22 22
  */
23 23
 class Principal extends DAV\Node implements IPrincipal, DAV\IProperties, IACL {
24 24
 
25
-    /**
26
-     * Struct with principal information.
27
-     *
28
-     * @var array
29
-     */
30
-    protected $principalProperties;
31
-
32
-    /**
33
-     * Principal backend
34
-     *
35
-     * @var PrincipalBackend\BackendInterface
36
-     */
37
-    protected $principalBackend;
38
-
39
-    /**
40
-     * Creates the principal object
41
-     *
42
-     * @param IPrincipalBackend $principalBackend
43
-     * @param array $principalProperties
44
-     */
45
-    public function __construct(PrincipalBackend\BackendInterface $principalBackend, array $principalProperties = []) {
46
-
47
-        if (!isset($principalProperties['uri'])) {
48
-            throw new DAV\Exception('The principal properties must at least contain the \'uri\' key');
49
-        }
50
-        $this->principalBackend = $principalBackend;
51
-        $this->principalProperties = $principalProperties;
52
-
53
-    }
54
-
55
-    /**
56
-     * Returns the full principal url
57
-     *
58
-     * @return string
59
-     */
60
-    public function getPrincipalUrl() {
61
-
62
-        return $this->principalProperties['uri'];
63
-
64
-    }
65
-
66
-    /**
67
-     * Returns a list of alternative urls for a principal
68
-     *
69
-     * This can for example be an email address, or ldap url.
70
-     *
71
-     * @return array
72
-     */
73
-    public function getAlternateUriSet() {
74
-
75
-        $uris = [];
76
-        if (isset($this->principalProperties['{DAV:}alternate-URI-set'])) {
77
-
78
-            $uris = $this->principalProperties['{DAV:}alternate-URI-set'];
79
-
80
-        }
81
-
82
-        if (isset($this->principalProperties['{http://sabredav.org/ns}email-address'])) {
83
-            $uris[] = 'mailto:' . $this->principalProperties['{http://sabredav.org/ns}email-address'];
84
-        }
85
-
86
-        return array_unique($uris);
87
-
88
-    }
89
-
90
-    /**
91
-     * Returns the list of group members
92
-     *
93
-     * If this principal is a group, this function should return
94
-     * all member principal uri's for the group.
95
-     *
96
-     * @return array
97
-     */
98
-    public function getGroupMemberSet() {
99
-
100
-        return $this->principalBackend->getGroupMemberSet($this->principalProperties['uri']);
101
-
102
-    }
103
-
104
-    /**
105
-     * Returns the list of groups this principal is member of
106
-     *
107
-     * If this principal is a member of a (list of) groups, this function
108
-     * should return a list of principal uri's for it's members.
109
-     *
110
-     * @return array
111
-     */
112
-    public function getGroupMembership() {
113
-
114
-        return $this->principalBackend->getGroupMemberShip($this->principalProperties['uri']);
115
-
116
-    }
117
-
118
-    /**
119
-     * Sets a list of group members
120
-     *
121
-     * If this principal is a group, this method sets all the group members.
122
-     * The list of members is always overwritten, never appended to.
123
-     *
124
-     * This method should throw an exception if the members could not be set.
125
-     *
126
-     * @param array $groupMembers
127
-     * @return void
128
-     */
129
-    public function setGroupMemberSet(array $groupMembers) {
130
-
131
-        $this->principalBackend->setGroupMemberSet($this->principalProperties['uri'], $groupMembers);
132
-
133
-    }
134
-
135
-    /**
136
-     * Returns this principals name.
137
-     *
138
-     * @return string
139
-     */
140
-    public function getName() {
141
-
142
-        $uri = $this->principalProperties['uri'];
143
-        list(, $name) = URLUtil::splitPath($uri);
144
-        return $name;
145
-
146
-    }
147
-
148
-    /**
149
-     * Returns the name of the user
150
-     *
151
-     * @return string
152
-     */
153
-    public function getDisplayName() {
154
-
155
-        if (isset($this->principalProperties['{DAV:}displayname'])) {
156
-            return $this->principalProperties['{DAV:}displayname'];
157
-        } else {
158
-            return $this->getName();
159
-        }
160
-
161
-    }
162
-
163
-    /**
164
-     * Returns a list of properties
165
-     *
166
-     * @param array $requestedProperties
167
-     * @return array
168
-     */
169
-    public function getProperties($requestedProperties) {
170
-
171
-        $newProperties = [];
172
-        foreach ($requestedProperties as $propName) {
173
-
174
-            if (isset($this->principalProperties[$propName])) {
175
-                $newProperties[$propName] = $this->principalProperties[$propName];
176
-            }
177
-
178
-        }
179
-
180
-        return $newProperties;
181
-
182
-    }
183
-
184
-    /**
185
-     * Updates properties on this node.
186
-     *
187
-     * This method received a PropPatch object, which contains all the
188
-     * information about the update.
189
-     *
190
-     * To update specific properties, call the 'handle' method on this object.
191
-     * Read the PropPatch documentation for more information.
192
-     *
193
-     * @param DAV\PropPatch $propPatch
194
-     * @return void
195
-     */
196
-    public function propPatch(DAV\PropPatch $propPatch) {
197
-
198
-        return $this->principalBackend->updatePrincipal(
199
-            $this->principalProperties['uri'],
200
-            $propPatch
201
-        );
202
-
203
-    }
204
-
205
-    /**
206
-     * Returns the owner principal
207
-     *
208
-     * This must be a url to a principal, or null if there's no owner
209
-     *
210
-     * @return string|null
211
-     */
212
-    public function getOwner() {
213
-
214
-        return $this->principalProperties['uri'];
215
-
216
-
217
-    }
218
-
219
-    /**
220
-     * Returns a group principal
221
-     *
222
-     * This must be a url to a principal, or null if there's no owner
223
-     *
224
-     * @return string|null
225
-     */
226
-    public function getGroup() {
227
-
228
-        return null;
229
-
230
-    }
231
-
232
-    /**
233
-     * Returns a list of ACE's for this node.
234
-     *
235
-     * Each ACE has the following properties:
236
-     *   * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
237
-     *     currently the only supported privileges
238
-     *   * 'principal', a url to the principal who owns the node
239
-     *   * 'protected' (optional), indicating that this ACE is not allowed to
240
-     *      be updated.
241
-     *
242
-     * @return array
243
-     */
244
-    public function getACL() {
245
-
246
-        return [
247
-            [
248
-                'privilege' => '{DAV:}read',
249
-                'principal' => '{DAV:}authenticated',
250
-                'protected' => true,
251
-            ],
252
-        ];
253
-
254
-    }
255
-
256
-    /**
257
-     * Updates the ACL
258
-     *
259
-     * This method will receive a list of new ACE's.
260
-     *
261
-     * @param array $acl
262
-     * @return void
263
-     */
264
-    public function setACL(array $acl) {
265
-
266
-        throw new DAV\Exception\MethodNotAllowed('Updating ACLs is not allowed here');
267
-
268
-    }
269
-
270
-    /**
271
-     * Returns the list of supported privileges for this node.
272
-     *
273
-     * The returned data structure is a list of nested privileges.
274
-     * See Sabre\DAVACL\Plugin::getDefaultSupportedPrivilegeSet for a simple
275
-     * standard structure.
276
-     *
277
-     * If null is returned from this method, the default privilege set is used,
278
-     * which is fine for most common usecases.
279
-     *
280
-     * @return array|null
281
-     */
282
-    public function getSupportedPrivilegeSet() {
283
-
284
-        return null;
285
-
286
-    }
25
+	/**
26
+	 * Struct with principal information.
27
+	 *
28
+	 * @var array
29
+	 */
30
+	protected $principalProperties;
31
+
32
+	/**
33
+	 * Principal backend
34
+	 *
35
+	 * @var PrincipalBackend\BackendInterface
36
+	 */
37
+	protected $principalBackend;
38
+
39
+	/**
40
+	 * Creates the principal object
41
+	 *
42
+	 * @param IPrincipalBackend $principalBackend
43
+	 * @param array $principalProperties
44
+	 */
45
+	public function __construct(PrincipalBackend\BackendInterface $principalBackend, array $principalProperties = []) {
46
+
47
+		if (!isset($principalProperties['uri'])) {
48
+			throw new DAV\Exception('The principal properties must at least contain the \'uri\' key');
49
+		}
50
+		$this->principalBackend = $principalBackend;
51
+		$this->principalProperties = $principalProperties;
52
+
53
+	}
54
+
55
+	/**
56
+	 * Returns the full principal url
57
+	 *
58
+	 * @return string
59
+	 */
60
+	public function getPrincipalUrl() {
61
+
62
+		return $this->principalProperties['uri'];
63
+
64
+	}
65
+
66
+	/**
67
+	 * Returns a list of alternative urls for a principal
68
+	 *
69
+	 * This can for example be an email address, or ldap url.
70
+	 *
71
+	 * @return array
72
+	 */
73
+	public function getAlternateUriSet() {
74
+
75
+		$uris = [];
76
+		if (isset($this->principalProperties['{DAV:}alternate-URI-set'])) {
77
+
78
+			$uris = $this->principalProperties['{DAV:}alternate-URI-set'];
79
+
80
+		}
81
+
82
+		if (isset($this->principalProperties['{http://sabredav.org/ns}email-address'])) {
83
+			$uris[] = 'mailto:' . $this->principalProperties['{http://sabredav.org/ns}email-address'];
84
+		}
85
+
86
+		return array_unique($uris);
87
+
88
+	}
89
+
90
+	/**
91
+	 * Returns the list of group members
92
+	 *
93
+	 * If this principal is a group, this function should return
94
+	 * all member principal uri's for the group.
95
+	 *
96
+	 * @return array
97
+	 */
98
+	public function getGroupMemberSet() {
99
+
100
+		return $this->principalBackend->getGroupMemberSet($this->principalProperties['uri']);
101
+
102
+	}
103
+
104
+	/**
105
+	 * Returns the list of groups this principal is member of
106
+	 *
107
+	 * If this principal is a member of a (list of) groups, this function
108
+	 * should return a list of principal uri's for it's members.
109
+	 *
110
+	 * @return array
111
+	 */
112
+	public function getGroupMembership() {
113
+
114
+		return $this->principalBackend->getGroupMemberShip($this->principalProperties['uri']);
115
+
116
+	}
117
+
118
+	/**
119
+	 * Sets a list of group members
120
+	 *
121
+	 * If this principal is a group, this method sets all the group members.
122
+	 * The list of members is always overwritten, never appended to.
123
+	 *
124
+	 * This method should throw an exception if the members could not be set.
125
+	 *
126
+	 * @param array $groupMembers
127
+	 * @return void
128
+	 */
129
+	public function setGroupMemberSet(array $groupMembers) {
130
+
131
+		$this->principalBackend->setGroupMemberSet($this->principalProperties['uri'], $groupMembers);
132
+
133
+	}
134
+
135
+	/**
136
+	 * Returns this principals name.
137
+	 *
138
+	 * @return string
139
+	 */
140
+	public function getName() {
141
+
142
+		$uri = $this->principalProperties['uri'];
143
+		list(, $name) = URLUtil::splitPath($uri);
144
+		return $name;
145
+
146
+	}
147
+
148
+	/**
149
+	 * Returns the name of the user
150
+	 *
151
+	 * @return string
152
+	 */
153
+	public function getDisplayName() {
154
+
155
+		if (isset($this->principalProperties['{DAV:}displayname'])) {
156
+			return $this->principalProperties['{DAV:}displayname'];
157
+		} else {
158
+			return $this->getName();
159
+		}
160
+
161
+	}
162
+
163
+	/**
164
+	 * Returns a list of properties
165
+	 *
166
+	 * @param array $requestedProperties
167
+	 * @return array
168
+	 */
169
+	public function getProperties($requestedProperties) {
170
+
171
+		$newProperties = [];
172
+		foreach ($requestedProperties as $propName) {
173
+
174
+			if (isset($this->principalProperties[$propName])) {
175
+				$newProperties[$propName] = $this->principalProperties[$propName];
176
+			}
177
+
178
+		}
179
+
180
+		return $newProperties;
181
+
182
+	}
183
+
184
+	/**
185
+	 * Updates properties on this node.
186
+	 *
187
+	 * This method received a PropPatch object, which contains all the
188
+	 * information about the update.
189
+	 *
190
+	 * To update specific properties, call the 'handle' method on this object.
191
+	 * Read the PropPatch documentation for more information.
192
+	 *
193
+	 * @param DAV\PropPatch $propPatch
194
+	 * @return void
195
+	 */
196
+	public function propPatch(DAV\PropPatch $propPatch) {
197
+
198
+		return $this->principalBackend->updatePrincipal(
199
+			$this->principalProperties['uri'],
200
+			$propPatch
201
+		);
202
+
203
+	}
204
+
205
+	/**
206
+	 * Returns the owner principal
207
+	 *
208
+	 * This must be a url to a principal, or null if there's no owner
209
+	 *
210
+	 * @return string|null
211
+	 */
212
+	public function getOwner() {
213
+
214
+		return $this->principalProperties['uri'];
215
+
216
+
217
+	}
218
+
219
+	/**
220
+	 * Returns a group principal
221
+	 *
222
+	 * This must be a url to a principal, or null if there's no owner
223
+	 *
224
+	 * @return string|null
225
+	 */
226
+	public function getGroup() {
227
+
228
+		return null;
229
+
230
+	}
231
+
232
+	/**
233
+	 * Returns a list of ACE's for this node.
234
+	 *
235
+	 * Each ACE has the following properties:
236
+	 *   * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
237
+	 *     currently the only supported privileges
238
+	 *   * 'principal', a url to the principal who owns the node
239
+	 *   * 'protected' (optional), indicating that this ACE is not allowed to
240
+	 *      be updated.
241
+	 *
242
+	 * @return array
243
+	 */
244
+	public function getACL() {
245
+
246
+		return [
247
+			[
248
+				'privilege' => '{DAV:}read',
249
+				'principal' => '{DAV:}authenticated',
250
+				'protected' => true,
251
+			],
252
+		];
253
+
254
+	}
255
+
256
+	/**
257
+	 * Updates the ACL
258
+	 *
259
+	 * This method will receive a list of new ACE's.
260
+	 *
261
+	 * @param array $acl
262
+	 * @return void
263
+	 */
264
+	public function setACL(array $acl) {
265
+
266
+		throw new DAV\Exception\MethodNotAllowed('Updating ACLs is not allowed here');
267
+
268
+	}
269
+
270
+	/**
271
+	 * Returns the list of supported privileges for this node.
272
+	 *
273
+	 * The returned data structure is a list of nested privileges.
274
+	 * See Sabre\DAVACL\Plugin::getDefaultSupportedPrivilegeSet for a simple
275
+	 * standard structure.
276
+	 *
277
+	 * If null is returned from this method, the default privilege set is used,
278
+	 * which is fine for most common usecases.
279
+	 *
280
+	 * @return array|null
281
+	 */
282
+	public function getSupportedPrivilegeSet() {
283
+
284
+		return null;
285
+
286
+	}
287 287
 
288 288
 }
Please login to merge, or discard this patch.
libraries/SabreDAV/DAVACL/PrincipalBackend/PDO.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@
 block discarded – undo
65 65
     /**
66 66
      * Sets up the backend.
67 67
      *
68
-     * @param PDO $pdo
68
+     * @param \PDO $pdo
69 69
      */
70 70
     function __construct(\PDO $pdo) {
71 71
 
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
      * @return array
241 241
      */
242 242
     function searchPrincipals($prefixPath, array $searchProperties, $test = 'allof') {
243
-        if (count($searchProperties) == 0) return [];    //No criteria
243
+        if (count($searchProperties) == 0) return []; //No criteria
244 244
 
245 245
         $query = sprintf('SELECT uri FROM %s WHERE ', $this->tableName);
246 246
         $values = [];
@@ -303,11 +303,11 @@  discard block
 block discarded – undo
303 303
         if ($value == null) return null;
304 304
 
305 305
         $uri = null;
306
-        switch ($scheme){
306
+        switch ($scheme) {
307 307
             case "mailto":
308 308
                 $query = sprintf('SELECT uri FROM %s WHERE lower(email)=lower(?)', $this->tableName);
309 309
                 $stmt = $this->pdo->prepare($query);
310
-                $stmt->execute([ $value ]);
310
+                $stmt->execute([$value]);
311 311
             
312 312
                 while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
313 313
                     // Checking if the principal is in the prefix
@@ -383,7 +383,7 @@  discard block
 block discarded – undo
383 383
     function setGroupMemberSet($principal, array $members) {
384 384
 
385 385
         // Grabbing the list of principal id's.
386
-        $stmt = $this->pdo->prepare(sprintf('SELECT id, uri FROM %s WHERE uri IN (? %s);',$this->tableName, str_repeat(', ? ', count($members))));
386
+        $stmt = $this->pdo->prepare(sprintf('SELECT id, uri FROM %s WHERE uri IN (? %s);', $this->tableName, str_repeat(', ? ', count($members))));
387 387
         $stmt->execute(array_merge([$principal], $members));
388 388
 
389 389
         $memberIds = [];
Please login to merge, or discard this patch.
Indentation   +405 added lines, -405 removed lines patch added patch discarded remove patch
@@ -19,415 +19,415 @@
 block discarded – undo
19 19
  */
20 20
 class PDO extends AbstractBackend implements CreatePrincipalSupport {
21 21
 
22
-    /**
23
-     * PDO table name for 'principals'
24
-     *
25
-     * @var string
26
-     */
27
-    public $tableName = 'principals';
28
-
29
-    /**
30
-     * PDO table name for 'group members'
31
-     *
32
-     * @var string
33
-     */
34
-    public $groupMembersTableName = 'groupmembers';
35
-
36
-    /**
37
-     * pdo
38
-     *
39
-     * @var PDO
40
-     */
41
-    protected $pdo;
42
-
43
-    /**
44
-     * A list of additional fields to support
45
-     *
46
-     * @var array
47
-     */
48
-    protected $fieldMap = [
49
-
50
-        /**
51
-         * This property can be used to display the users' real name.
52
-         */
53
-        '{DAV:}displayname' => [
54
-            'dbField' => 'displayname',
55
-        ],
56
-
57
-        /**
58
-         * This is the users' primary email-address.
59
-         */
60
-        '{http://sabredav.org/ns}email-address' => [
61
-            'dbField' => 'email',
62
-        ],
63
-    ];
64
-
65
-    /**
66
-     * Sets up the backend.
67
-     *
68
-     * @param PDO $pdo
69
-     */
70
-    public function __construct(\PDO $pdo) {
71
-
72
-        $this->pdo = $pdo;
73
-
74
-    }
75
-
76
-    /**
77
-     * Returns a list of principals based on a prefix.
78
-     *
79
-     * This prefix will often contain something like 'principals'. You are only
80
-     * expected to return principals that are in this base path.
81
-     *
82
-     * You are expected to return at least a 'uri' for every user, you can
83
-     * return any additional properties if you wish so. Common properties are:
84
-     *   {DAV:}displayname
85
-     *   {http://sabredav.org/ns}email-address - This is a custom SabreDAV
86
-     *     field that's actualy injected in a number of other properties. If
87
-     *     you have an email address, use this property.
88
-     *
89
-     * @param string $prefixPath
90
-     * @return array
91
-     */
92
-    public function getPrincipalsByPrefix($prefixPath) {
93
-
94
-        $fields = [
95
-            'uri',
96
-        ];
97
-
98
-        foreach ($this->fieldMap as $key => $value) {
99
-            $fields[] = $value['dbField'];
100
-        }
101
-        $result = $this->pdo->query(sprintf('SELECT %s FROM %s', implode(',', $fields), $this->tableName));
102
-
103
-        $principals = [];
104
-
105
-        while ($row = $result->fetch(\PDO::FETCH_ASSOC)) {
106
-
107
-            // Checking if the principal is in the prefix
108
-            list($rowPrefix) = URLUtil::splitPath($row['uri']);
109
-            if ($rowPrefix !== $prefixPath) continue;
110
-
111
-            $principal = [
112
-                'uri' => $row['uri'],
113
-            ];
114
-            foreach ($this->fieldMap as $key => $value) {
115
-                if ($row[$value['dbField']]) {
116
-                    $principal[$key] = $row[$value['dbField']];
117
-                }
118
-            }
119
-            $principals[] = $principal;
120
-
121
-        }
122
-
123
-        return $principals;
124
-
125
-    }
126
-
127
-    /**
128
-     * Returns a specific principal, specified by it's path.
129
-     * The returned structure should be the exact same as from
130
-     * getPrincipalsByPrefix.
131
-     *
132
-     * @param string $path
133
-     * @return array
134
-     */
135
-    public function getPrincipalByPath($path) {
136
-
137
-        $fields = [
138
-            'id',
139
-            'uri',
140
-        ];
141
-
142
-        foreach ($this->fieldMap as $key => $value) {
143
-            $fields[] = $value['dbField'];
144
-        }
145
-        $stmt = $this->pdo->prepare(sprintf('SELECT %s FROM %s WHERE uri = ?', implode(',', $fields), $this->tableName));
146
-        $stmt->execute([$path]);
147
-
148
-        $row = $stmt->fetch(\PDO::FETCH_ASSOC);
149
-        if (!$row) return;
150
-
151
-        $principal = [
152
-            'id'  => $row['id'],
153
-            'uri' => $row['uri'],
154
-        ];
155
-        foreach ($this->fieldMap as $key => $value) {
156
-            if ($row[$value['dbField']]) {
157
-                $principal[$key] = $row[$value['dbField']];
158
-            }
159
-        }
160
-        return $principal;
161
-
162
-    }
163
-
164
-    /**
165
-     * Updates one ore more webdav properties on a principal.
166
-     *
167
-     * The list of mutations is stored in a Sabre\DAV\PropPatch object.
168
-     * To do the actual updates, you must tell this object which properties
169
-     * you're going to process with the handle() method.
170
-     *
171
-     * Calling the handle method is like telling the PropPatch object "I
172
-     * promise I can handle updating this property".
173
-     *
174
-     * Read the PropPatch documenation for more info and examples.
175
-     *
176
-     * @param string $path
177
-     * @param DAV\PropPatch $propPatch
178
-     */
179
-    public function updatePrincipal($path, DAV\PropPatch $propPatch) {
180
-
181
-        $propPatch->handle(array_keys($this->fieldMap), function($properties) use ($path) {
182
-
183
-            $query = sprintf('UPDATE %s SET ', $this->tableName);
184
-            $first = true;
185
-
186
-            $values = [];
187
-
188
-            foreach ($properties as $key => $value) {
189
-
190
-                $dbField = $this->fieldMap[$key]['dbField'];
191
-
192
-                if (!$first) {
193
-                    $query .= ', ';
194
-                }
195
-                $first = false;
196
-                $query .= $dbField . ' = :' . $dbField;
197
-                $values[$dbField] = $value;
198
-
199
-            }
200
-
201
-            $query .= " WHERE uri = :uri";
202
-            $values['uri'] = $path;
203
-
204
-            $stmt = $this->pdo->prepare($query);
205
-            $stmt->execute($values);
206
-
207
-            return true;
208
-
209
-        });
210
-
211
-    }
212
-
213
-    /**
214
-     * This method is used to search for principals matching a set of
215
-     * properties.
216
-     *
217
-     * This search is specifically used by RFC3744's principal-property-search
218
-     * REPORT.
219
-     *
220
-     * The actual search should be a unicode-non-case-sensitive search. The
221
-     * keys in searchProperties are the WebDAV property names, while the values
222
-     * are the property values to search on.
223
-     *
224
-     * By default, if multiple properties are submitted to this method, the
225
-     * various properties should be combined with 'AND'. If $test is set to
226
-     * 'anyof', it should be combined using 'OR'.
227
-     *
228
-     * This method should simply return an array with full principal uri's.
229
-     *
230
-     * If somebody attempted to search on a property the backend does not
231
-     * support, you should simply return 0 results.
232
-     *
233
-     * You can also just return 0 results if you choose to not support
234
-     * searching at all, but keep in mind that this may stop certain features
235
-     * from working.
236
-     *
237
-     * @param string $prefixPath
238
-     * @param array $searchProperties
239
-     * @param string $test
240
-     * @return array
241
-     */
242
-    public function searchPrincipals($prefixPath, array $searchProperties, $test = 'allof') {
243
-        if (count($searchProperties) == 0) return [];    //No criteria
244
-
245
-        $query = sprintf('SELECT uri FROM %s WHERE ', $this->tableName);
246
-        $values = [];
247
-        foreach ($searchProperties as $property => $value) {
248
-            switch ($property) {
249
-                case '{DAV:}displayname' :
250
-                    $column = "displayname";
251
-                    break;
252
-                case '{http://sabredav.org/ns}email-address' :
253
-                    $column = "email";
254
-                    break;
255
-                default :
256
-                    // Unsupported property
257
-                    return [];
258
-            }
259
-            if (count($values) > 0) $query .= (strcmp($test, "anyof") == 0 ? " || " : " && ");
260
-            $query .= 'lower(' . $column . ') LIKE lower(?)';
261
-            $values[] = '%' . $value . '%';
262
-
263
-        }
264
-        $stmt = $this->pdo->prepare($query);
265
-        $stmt->execute($values);
266
-
267
-        $principals = [];
268
-        while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
269
-
270
-            // Checking if the principal is in the prefix
271
-            list($rowPrefix) = URLUtil::splitPath($row['uri']);
272
-            if ($rowPrefix !== $prefixPath) continue;
273
-
274
-            $principals[] = $row['uri'];
275
-
276
-        }
277
-
278
-        return $principals;
279
-
280
-    }
281
-
282
-    /**
283
-     * Finds a principal by its URI.
284
-     *
285
-     * This method may receive any type of uri, but mailto: addresses will be
286
-     * the most common.
287
-     *
288
-     * Implementation of this API is optional. It is currently used by the
289
-     * CalDAV system to find principals based on their email addresses. If this
290
-     * API is not implemented, some features may not work correctly.
291
-     *
292
-     * This method must return a relative principal path, or null, if the
293
-     * principal was not found or you refuse to find it.
294
-     *
295
-     * @param string $uri
296
-     * @param string $principalPrefix
297
-     * @return string
298
-     */
299
-    public function findByUri($uri, $principalPrefix) {
300
-        $value = null;
301
-        $scheme = null;
302
-        list($scheme, $value) = explode(":", $uri, 2);
303
-        if ($value === null) return null;
304
-
305
-        $uri = null;
306
-        switch ($scheme){
307
-            case "mailto":
308
-                $query = sprintf('SELECT uri FROM %s WHERE lower(email)=lower(?)', $this->tableName);
309
-                $stmt = $this->pdo->prepare($query);
310
-                $stmt->execute([ $value ]);
22
+	/**
23
+	 * PDO table name for 'principals'
24
+	 *
25
+	 * @var string
26
+	 */
27
+	public $tableName = 'principals';
28
+
29
+	/**
30
+	 * PDO table name for 'group members'
31
+	 *
32
+	 * @var string
33
+	 */
34
+	public $groupMembersTableName = 'groupmembers';
35
+
36
+	/**
37
+	 * pdo
38
+	 *
39
+	 * @var PDO
40
+	 */
41
+	protected $pdo;
42
+
43
+	/**
44
+	 * A list of additional fields to support
45
+	 *
46
+	 * @var array
47
+	 */
48
+	protected $fieldMap = [
49
+
50
+		/**
51
+		 * This property can be used to display the users' real name.
52
+		 */
53
+		'{DAV:}displayname' => [
54
+			'dbField' => 'displayname',
55
+		],
56
+
57
+		/**
58
+		 * This is the users' primary email-address.
59
+		 */
60
+		'{http://sabredav.org/ns}email-address' => [
61
+			'dbField' => 'email',
62
+		],
63
+	];
64
+
65
+	/**
66
+	 * Sets up the backend.
67
+	 *
68
+	 * @param PDO $pdo
69
+	 */
70
+	public function __construct(\PDO $pdo) {
71
+
72
+		$this->pdo = $pdo;
73
+
74
+	}
75
+
76
+	/**
77
+	 * Returns a list of principals based on a prefix.
78
+	 *
79
+	 * This prefix will often contain something like 'principals'. You are only
80
+	 * expected to return principals that are in this base path.
81
+	 *
82
+	 * You are expected to return at least a 'uri' for every user, you can
83
+	 * return any additional properties if you wish so. Common properties are:
84
+	 *   {DAV:}displayname
85
+	 *   {http://sabredav.org/ns}email-address - This is a custom SabreDAV
86
+	 *     field that's actualy injected in a number of other properties. If
87
+	 *     you have an email address, use this property.
88
+	 *
89
+	 * @param string $prefixPath
90
+	 * @return array
91
+	 */
92
+	public function getPrincipalsByPrefix($prefixPath) {
93
+
94
+		$fields = [
95
+			'uri',
96
+		];
97
+
98
+		foreach ($this->fieldMap as $key => $value) {
99
+			$fields[] = $value['dbField'];
100
+		}
101
+		$result = $this->pdo->query(sprintf('SELECT %s FROM %s', implode(',', $fields), $this->tableName));
102
+
103
+		$principals = [];
104
+
105
+		while ($row = $result->fetch(\PDO::FETCH_ASSOC)) {
106
+
107
+			// Checking if the principal is in the prefix
108
+			list($rowPrefix) = URLUtil::splitPath($row['uri']);
109
+			if ($rowPrefix !== $prefixPath) continue;
110
+
111
+			$principal = [
112
+				'uri' => $row['uri'],
113
+			];
114
+			foreach ($this->fieldMap as $key => $value) {
115
+				if ($row[$value['dbField']]) {
116
+					$principal[$key] = $row[$value['dbField']];
117
+				}
118
+			}
119
+			$principals[] = $principal;
120
+
121
+		}
122
+
123
+		return $principals;
124
+
125
+	}
126
+
127
+	/**
128
+	 * Returns a specific principal, specified by it's path.
129
+	 * The returned structure should be the exact same as from
130
+	 * getPrincipalsByPrefix.
131
+	 *
132
+	 * @param string $path
133
+	 * @return array
134
+	 */
135
+	public function getPrincipalByPath($path) {
136
+
137
+		$fields = [
138
+			'id',
139
+			'uri',
140
+		];
141
+
142
+		foreach ($this->fieldMap as $key => $value) {
143
+			$fields[] = $value['dbField'];
144
+		}
145
+		$stmt = $this->pdo->prepare(sprintf('SELECT %s FROM %s WHERE uri = ?', implode(',', $fields), $this->tableName));
146
+		$stmt->execute([$path]);
147
+
148
+		$row = $stmt->fetch(\PDO::FETCH_ASSOC);
149
+		if (!$row) return;
150
+
151
+		$principal = [
152
+			'id'  => $row['id'],
153
+			'uri' => $row['uri'],
154
+		];
155
+		foreach ($this->fieldMap as $key => $value) {
156
+			if ($row[$value['dbField']]) {
157
+				$principal[$key] = $row[$value['dbField']];
158
+			}
159
+		}
160
+		return $principal;
161
+
162
+	}
163
+
164
+	/**
165
+	 * Updates one ore more webdav properties on a principal.
166
+	 *
167
+	 * The list of mutations is stored in a Sabre\DAV\PropPatch object.
168
+	 * To do the actual updates, you must tell this object which properties
169
+	 * you're going to process with the handle() method.
170
+	 *
171
+	 * Calling the handle method is like telling the PropPatch object "I
172
+	 * promise I can handle updating this property".
173
+	 *
174
+	 * Read the PropPatch documenation for more info and examples.
175
+	 *
176
+	 * @param string $path
177
+	 * @param DAV\PropPatch $propPatch
178
+	 */
179
+	public function updatePrincipal($path, DAV\PropPatch $propPatch) {
180
+
181
+		$propPatch->handle(array_keys($this->fieldMap), function($properties) use ($path) {
182
+
183
+			$query = sprintf('UPDATE %s SET ', $this->tableName);
184
+			$first = true;
185
+
186
+			$values = [];
187
+
188
+			foreach ($properties as $key => $value) {
189
+
190
+				$dbField = $this->fieldMap[$key]['dbField'];
191
+
192
+				if (!$first) {
193
+					$query .= ', ';
194
+				}
195
+				$first = false;
196
+				$query .= $dbField . ' = :' . $dbField;
197
+				$values[$dbField] = $value;
198
+
199
+			}
200
+
201
+			$query .= " WHERE uri = :uri";
202
+			$values['uri'] = $path;
203
+
204
+			$stmt = $this->pdo->prepare($query);
205
+			$stmt->execute($values);
206
+
207
+			return true;
208
+
209
+		});
210
+
211
+	}
212
+
213
+	/**
214
+	 * This method is used to search for principals matching a set of
215
+	 * properties.
216
+	 *
217
+	 * This search is specifically used by RFC3744's principal-property-search
218
+	 * REPORT.
219
+	 *
220
+	 * The actual search should be a unicode-non-case-sensitive search. The
221
+	 * keys in searchProperties are the WebDAV property names, while the values
222
+	 * are the property values to search on.
223
+	 *
224
+	 * By default, if multiple properties are submitted to this method, the
225
+	 * various properties should be combined with 'AND'. If $test is set to
226
+	 * 'anyof', it should be combined using 'OR'.
227
+	 *
228
+	 * This method should simply return an array with full principal uri's.
229
+	 *
230
+	 * If somebody attempted to search on a property the backend does not
231
+	 * support, you should simply return 0 results.
232
+	 *
233
+	 * You can also just return 0 results if you choose to not support
234
+	 * searching at all, but keep in mind that this may stop certain features
235
+	 * from working.
236
+	 *
237
+	 * @param string $prefixPath
238
+	 * @param array $searchProperties
239
+	 * @param string $test
240
+	 * @return array
241
+	 */
242
+	public function searchPrincipals($prefixPath, array $searchProperties, $test = 'allof') {
243
+		if (count($searchProperties) == 0) return [];    //No criteria
244
+
245
+		$query = sprintf('SELECT uri FROM %s WHERE ', $this->tableName);
246
+		$values = [];
247
+		foreach ($searchProperties as $property => $value) {
248
+			switch ($property) {
249
+				case '{DAV:}displayname' :
250
+					$column = "displayname";
251
+					break;
252
+				case '{http://sabredav.org/ns}email-address' :
253
+					$column = "email";
254
+					break;
255
+				default :
256
+					// Unsupported property
257
+					return [];
258
+			}
259
+			if (count($values) > 0) $query .= (strcmp($test, "anyof") == 0 ? " || " : " && ");
260
+			$query .= 'lower(' . $column . ') LIKE lower(?)';
261
+			$values[] = '%' . $value . '%';
262
+
263
+		}
264
+		$stmt = $this->pdo->prepare($query);
265
+		$stmt->execute($values);
266
+
267
+		$principals = [];
268
+		while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
269
+
270
+			// Checking if the principal is in the prefix
271
+			list($rowPrefix) = URLUtil::splitPath($row['uri']);
272
+			if ($rowPrefix !== $prefixPath) continue;
273
+
274
+			$principals[] = $row['uri'];
275
+
276
+		}
277
+
278
+		return $principals;
279
+
280
+	}
281
+
282
+	/**
283
+	 * Finds a principal by its URI.
284
+	 *
285
+	 * This method may receive any type of uri, but mailto: addresses will be
286
+	 * the most common.
287
+	 *
288
+	 * Implementation of this API is optional. It is currently used by the
289
+	 * CalDAV system to find principals based on their email addresses. If this
290
+	 * API is not implemented, some features may not work correctly.
291
+	 *
292
+	 * This method must return a relative principal path, or null, if the
293
+	 * principal was not found or you refuse to find it.
294
+	 *
295
+	 * @param string $uri
296
+	 * @param string $principalPrefix
297
+	 * @return string
298
+	 */
299
+	public function findByUri($uri, $principalPrefix) {
300
+		$value = null;
301
+		$scheme = null;
302
+		list($scheme, $value) = explode(":", $uri, 2);
303
+		if ($value === null) return null;
304
+
305
+		$uri = null;
306
+		switch ($scheme){
307
+			case "mailto":
308
+				$query = sprintf('SELECT uri FROM %s WHERE lower(email)=lower(?)', $this->tableName);
309
+				$stmt = $this->pdo->prepare($query);
310
+				$stmt->execute([ $value ]);
311 311
             
312
-                while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
313
-                    // Checking if the principal is in the prefix
314
-                    list($rowPrefix) = URLUtil::splitPath($row['uri']);
315
-                    if ($rowPrefix !== $principalPrefix) continue;
312
+				while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
313
+					// Checking if the principal is in the prefix
314
+					list($rowPrefix) = URLUtil::splitPath($row['uri']);
315
+					if ($rowPrefix !== $principalPrefix) continue;
316 316
                     
317
-                    $uri = $row['uri'];
318
-                    break; //Stop on first match
319
-                }
320
-                break;
321
-            default:
322
-                //unsupported uri scheme
323
-                return null;
324
-        }
325
-        return $uri;
326
-    }
327
-
328
-    /**
329
-     * Returns the list of members for a group-principal
330
-     *
331
-     * @param string $principal
332
-     * @return array
333
-     */
334
-    public function getGroupMemberSet($principal) {
335
-
336
-        $principal = $this->getPrincipalByPath($principal);
337
-        if (!$principal) throw new DAV\Exception('Principal not found');
317
+					$uri = $row['uri'];
318
+					break; //Stop on first match
319
+				}
320
+				break;
321
+			default:
322
+				//unsupported uri scheme
323
+				return null;
324
+		}
325
+		return $uri;
326
+	}
327
+
328
+	/**
329
+	 * Returns the list of members for a group-principal
330
+	 *
331
+	 * @param string $principal
332
+	 * @return array
333
+	 */
334
+	public function getGroupMemberSet($principal) {
335
+
336
+		$principal = $this->getPrincipalByPath($principal);
337
+		if (!$principal) throw new DAV\Exception('Principal not found');
338 338
 
339 339
 		$query = 'SELECT principals.uri as uri FROM %s AS groupmembers LEFT JOIN %s AS principals ON groupmembers.member_id = principals.id WHERE groupmembers.principal_id = ?';
340
-        $query = sprintf($query, $this->groupMembersTableName, $this->tableName);
340
+		$query = sprintf($query, $this->groupMembersTableName, $this->tableName);
341 341
 		$stmt = $this->pdo->prepare($query);
342
-        $stmt->execute([$principal['id']]);
343
-
344
-        $result = [];
345
-        while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
346
-            $result[] = $row['uri'];
347
-        }
348
-        return $result;
349
-
350
-    }
351
-
352
-    /**
353
-     * Returns the list of groups a principal is a member of
354
-     *
355
-     * @param string $principal
356
-     * @return array
357
-     */
358
-    public function getGroupMembership($principal) {
359
-
360
-        $principal = $this->getPrincipalByPath($principal);
361
-        if (!$principal) throw new DAV\Exception('Principal not found');
362
-
363
-        $stmt = $this->pdo->prepare(sprintf('SELECT principals.uri as uri FROM %s AS groupmembers LEFT JOIN %s AS principals ON groupmembers.principal_id = principals.id WHERE groupmembers.member_id = ?', $this->groupMembersTableName, $this->tableName));
364
-        $stmt->execute([$principal['id']]);
365
-
366
-        $result = [];
367
-        while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
368
-            $result[] = $row['uri'];
369
-        }
370
-        return $result;
371
-
372
-    }
373
-
374
-    /**
375
-     * Updates the list of group members for a group principal.
376
-     *
377
-     * The principals should be passed as a list of uri's.
378
-     *
379
-     * @param string $principal
380
-     * @param array $members
381
-     * @return void
382
-     */
383
-    public function setGroupMemberSet($principal, array $members) {
384
-
385
-        // Grabbing the list of principal id's.
386
-        $stmt = $this->pdo->prepare(sprintf('SELECT id, uri FROM %s WHERE uri IN (? %s);',$this->tableName, str_repeat(', ? ', count($members))));
387
-        $stmt->execute(array_merge([$principal], $members));
388
-
389
-        $memberIds = [];
390
-        $principalId = null;
391
-
392
-        while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
393
-            if ($row['uri'] == $principal) {
394
-                $principalId = $row['id'];
395
-            } else {
396
-                $memberIds[] = $row['id'];
397
-            }
398
-        }
399
-        if (!$principalId) throw new DAV\Exception('Principal not found');
400
-
401
-        // Wiping out old members
402
-        $stmt = $this->pdo->prepare(sprintf('DELETE FROM %s WHERE principal_id = ?;', $this->groupMembersTableName));
403
-        $stmt->execute([$principalId]);
404
-
405
-        foreach ($memberIds as $memberId) {
406
-
407
-            $stmt = $this->pdo->prepare('INSERT INTO ' . $this->groupMembersTableName . ' (principal_id, member_id) VALUES (?, ?);');
408
-            $stmt->execute([$principalId, $memberId]);
409
-
410
-        }
411
-
412
-    }
413
-
414
-    /**
415
-     * Creates a new principal.
416
-     *
417
-     * This method receives a full path for the new principal. The mkCol object
418
-     * contains any additional webdav properties specified during the creation
419
-     * of the principal.
420
-     *
421
-     * @param string $path
422
-     * @param MkCol $mkCol
423
-     * @return void
424
-     */
425
-    public function createPrincipal($path, MkCol $mkCol) {
426
-
427
-        $stmt = $this->pdo->prepare('INSERT INTO ' . $this->tableName . ' (uri) VALUES (?)');
428
-        $stmt->execute([$path]);
429
-        $this->updatePrincipal($path, $mkCol);
430
-
431
-    }
342
+		$stmt->execute([$principal['id']]);
343
+
344
+		$result = [];
345
+		while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
346
+			$result[] = $row['uri'];
347
+		}
348
+		return $result;
349
+
350
+	}
351
+
352
+	/**
353
+	 * Returns the list of groups a principal is a member of
354
+	 *
355
+	 * @param string $principal
356
+	 * @return array
357
+	 */
358
+	public function getGroupMembership($principal) {
359
+
360
+		$principal = $this->getPrincipalByPath($principal);
361
+		if (!$principal) throw new DAV\Exception('Principal not found');
362
+
363
+		$stmt = $this->pdo->prepare(sprintf('SELECT principals.uri as uri FROM %s AS groupmembers LEFT JOIN %s AS principals ON groupmembers.principal_id = principals.id WHERE groupmembers.member_id = ?', $this->groupMembersTableName, $this->tableName));
364
+		$stmt->execute([$principal['id']]);
365
+
366
+		$result = [];
367
+		while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
368
+			$result[] = $row['uri'];
369
+		}
370
+		return $result;
371
+
372
+	}
373
+
374
+	/**
375
+	 * Updates the list of group members for a group principal.
376
+	 *
377
+	 * The principals should be passed as a list of uri's.
378
+	 *
379
+	 * @param string $principal
380
+	 * @param array $members
381
+	 * @return void
382
+	 */
383
+	public function setGroupMemberSet($principal, array $members) {
384
+
385
+		// Grabbing the list of principal id's.
386
+		$stmt = $this->pdo->prepare(sprintf('SELECT id, uri FROM %s WHERE uri IN (? %s);',$this->tableName, str_repeat(', ? ', count($members))));
387
+		$stmt->execute(array_merge([$principal], $members));
388
+
389
+		$memberIds = [];
390
+		$principalId = null;
391
+
392
+		while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
393
+			if ($row['uri'] == $principal) {
394
+				$principalId = $row['id'];
395
+			} else {
396
+				$memberIds[] = $row['id'];
397
+			}
398
+		}
399
+		if (!$principalId) throw new DAV\Exception('Principal not found');
400
+
401
+		// Wiping out old members
402
+		$stmt = $this->pdo->prepare(sprintf('DELETE FROM %s WHERE principal_id = ?;', $this->groupMembersTableName));
403
+		$stmt->execute([$principalId]);
404
+
405
+		foreach ($memberIds as $memberId) {
406
+
407
+			$stmt = $this->pdo->prepare('INSERT INTO ' . $this->groupMembersTableName . ' (principal_id, member_id) VALUES (?, ?);');
408
+			$stmt->execute([$principalId, $memberId]);
409
+
410
+		}
411
+
412
+	}
413
+
414
+	/**
415
+	 * Creates a new principal.
416
+	 *
417
+	 * This method receives a full path for the new principal. The mkCol object
418
+	 * contains any additional webdav properties specified during the creation
419
+	 * of the principal.
420
+	 *
421
+	 * @param string $path
422
+	 * @param MkCol $mkCol
423
+	 * @return void
424
+	 */
425
+	public function createPrincipal($path, MkCol $mkCol) {
426
+
427
+		$stmt = $this->pdo->prepare('INSERT INTO ' . $this->tableName . ' (uri) VALUES (?)');
428
+		$stmt->execute([$path]);
429
+		$this->updatePrincipal($path, $mkCol);
430
+
431
+	}
432 432
 
433 433
 }
Please login to merge, or discard this patch.
Braces   +31 added lines, -10 removed lines patch added patch discarded remove patch
@@ -106,7 +106,9 @@  discard block
 block discarded – undo
106 106
 
107 107
             // Checking if the principal is in the prefix
108 108
             list($rowPrefix) = URLUtil::splitPath($row['uri']);
109
-            if ($rowPrefix !== $prefixPath) continue;
109
+            if ($rowPrefix !== $prefixPath) {
110
+            	continue;
111
+            }
110 112
 
111 113
             $principal = [
112 114
                 'uri' => $row['uri'],
@@ -146,7 +148,9 @@  discard block
 block discarded – undo
146 148
         $stmt->execute([$path]);
147 149
 
148 150
         $row = $stmt->fetch(\PDO::FETCH_ASSOC);
149
-        if (!$row) return;
151
+        if (!$row) {
152
+        	return;
153
+        }
150 154
 
151 155
         $principal = [
152 156
             'id'  => $row['id'],
@@ -240,7 +244,10 @@  discard block
 block discarded – undo
240 244
      * @return array
241 245
      */
242 246
     public function searchPrincipals($prefixPath, array $searchProperties, $test = 'allof') {
243
-        if (count($searchProperties) == 0) return [];    //No criteria
247
+        if (count($searchProperties) == 0) {
248
+        	return [];
249
+        }
250
+        //No criteria
244 251
 
245 252
         $query = sprintf('SELECT uri FROM %s WHERE ', $this->tableName);
246 253
         $values = [];
@@ -256,7 +263,9 @@  discard block
 block discarded – undo
256 263
                     // Unsupported property
257 264
                     return [];
258 265
             }
259
-            if (count($values) > 0) $query .= (strcmp($test, "anyof") == 0 ? " || " : " && ");
266
+            if (count($values) > 0) {
267
+            	$query .= (strcmp($test, "anyof") == 0 ? " || " : " && ");
268
+            }
260 269
             $query .= 'lower(' . $column . ') LIKE lower(?)';
261 270
             $values[] = '%' . $value . '%';
262 271
 
@@ -269,7 +278,9 @@  discard block
 block discarded – undo
269 278
 
270 279
             // Checking if the principal is in the prefix
271 280
             list($rowPrefix) = URLUtil::splitPath($row['uri']);
272
-            if ($rowPrefix !== $prefixPath) continue;
281
+            if ($rowPrefix !== $prefixPath) {
282
+            	continue;
283
+            }
273 284
 
274 285
             $principals[] = $row['uri'];
275 286
 
@@ -300,7 +311,9 @@  discard block
 block discarded – undo
300 311
         $value = null;
301 312
         $scheme = null;
302 313
         list($scheme, $value) = explode(":", $uri, 2);
303
-        if ($value === null) return null;
314
+        if ($value === null) {
315
+        	return null;
316
+        }
304 317
 
305 318
         $uri = null;
306 319
         switch ($scheme){
@@ -312,7 +325,9 @@  discard block
 block discarded – undo
312 325
                 while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
313 326
                     // Checking if the principal is in the prefix
314 327
                     list($rowPrefix) = URLUtil::splitPath($row['uri']);
315
-                    if ($rowPrefix !== $principalPrefix) continue;
328
+                    if ($rowPrefix !== $principalPrefix) {
329
+                    	continue;
330
+                    }
316 331
                     
317 332
                     $uri = $row['uri'];
318 333
                     break; //Stop on first match
@@ -334,7 +349,9 @@  discard block
 block discarded – undo
334 349
     public function getGroupMemberSet($principal) {
335 350
 
336 351
         $principal = $this->getPrincipalByPath($principal);
337
-        if (!$principal) throw new DAV\Exception('Principal not found');
352
+        if (!$principal) {
353
+        	throw new DAV\Exception('Principal not found');
354
+        }
338 355
 
339 356
 		$query = 'SELECT principals.uri as uri FROM %s AS groupmembers LEFT JOIN %s AS principals ON groupmembers.member_id = principals.id WHERE groupmembers.principal_id = ?';
340 357
         $query = sprintf($query, $this->groupMembersTableName, $this->tableName);
@@ -358,7 +375,9 @@  discard block
 block discarded – undo
358 375
     public function getGroupMembership($principal) {
359 376
 
360 377
         $principal = $this->getPrincipalByPath($principal);
361
-        if (!$principal) throw new DAV\Exception('Principal not found');
378
+        if (!$principal) {
379
+        	throw new DAV\Exception('Principal not found');
380
+        }
362 381
 
363 382
         $stmt = $this->pdo->prepare(sprintf('SELECT principals.uri as uri FROM %s AS groupmembers LEFT JOIN %s AS principals ON groupmembers.principal_id = principals.id WHERE groupmembers.member_id = ?', $this->groupMembersTableName, $this->tableName));
364 383
         $stmt->execute([$principal['id']]);
@@ -396,7 +415,9 @@  discard block
 block discarded – undo
396 415
                 $memberIds[] = $row['id'];
397 416
             }
398 417
         }
399
-        if (!$principalId) throw new DAV\Exception('Principal not found');
418
+        if (!$principalId) {
419
+        	throw new DAV\Exception('Principal not found');
420
+        }
400 421
 
401 422
         // Wiping out old members
402 423
         $stmt = $this->pdo->prepare(sprintf('DELETE FROM %s WHERE principal_id = ?;', $this->groupMembersTableName));
Please login to merge, or discard this patch.
libraries/SabreDAV/DAVACL/Xml/Property/Acl.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -165,7 +165,7 @@
 block discarded – undo
165 165
      * the next element.
166 166
      *
167 167
      * @param Reader $reader
168
-     * @return mixed
168
+     * @return Acl
169 169
      */
170 170
     static function xmlDeserialize(Reader $reader) {
171 171
 
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -177,7 +177,7 @@
 block discarded – undo
177 177
 
178 178
         $privileges = [];
179 179
 
180
-        foreach ((array)$reader->parseInnerTree($elementMap) as $element) {
180
+        foreach ((array) $reader->parseInnerTree($elementMap) as $element) {
181 181
 
182 182
             if ($element['name'] !== '{DAV:}ace') {
183 183
                 continue;
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -136,7 +136,9 @@
 block discarded – undo
136 136
             }
137 137
             echo '<td>', $html->xmlName($privilege['privilege']), '</td>';
138 138
             echo '<td>';
139
-            if (!empty($privilege['protected'])) echo '(protected)';
139
+            if (!empty($privilege['protected'])) {
140
+            	echo '(protected)';
141
+            }
140 142
             echo '</td>';
141 143
             echo '</tr>';
142 144
 
Please login to merge, or discard this patch.
Indentation   +246 added lines, -246 removed lines patch added patch discarded remove patch
@@ -27,251 +27,251 @@
 block discarded – undo
27 27
  */
28 28
 class Acl implements Element, HtmlOutput {
29 29
 
30
-    /**
31
-     * List of privileges
32
-     *
33
-     * @var array
34
-     */
35
-    protected $privileges;
36
-
37
-    /**
38
-     * Whether or not the server base url is required to be prefixed when
39
-     * serializing the property.
40
-     *
41
-     * @var bool
42
-     */
43
-    protected $prefixBaseUrl;
44
-
45
-    /**
46
-     * Constructor
47
-     *
48
-     * This object requires a structure similar to the return value from
49
-     * Sabre\DAVACL\Plugin::getACL().
50
-     *
51
-     * Each privilege is a an array with at least a 'privilege' property, and a
52
-     * 'principal' property. A privilege may have a 'protected' property as
53
-     * well.
54
-     *
55
-     * The prefixBaseUrl should be set to false, if the supplied principal urls
56
-     * are already full urls. If this is kept to true, the servers base url
57
-     * will automatically be prefixed.
58
-     *
59
-     * @param array $privileges
60
-     * @param bool $prefixBaseUrl
61
-     */
62
-    public function __construct(array $privileges, $prefixBaseUrl = true) {
63
-
64
-        $this->privileges = $privileges;
65
-        $this->prefixBaseUrl = $prefixBaseUrl;
66
-
67
-    }
68
-
69
-    /**
70
-     * Returns the list of privileges for this property
71
-     *
72
-     * @return array
73
-     */
74
-    public function getPrivileges() {
75
-
76
-        return $this->privileges;
77
-
78
-    }
79
-
80
-    /**
81
-     * The xmlSerialize metod is called during xml writing.
82
-     *
83
-     * Use the $writer argument to write its own xml serialization.
84
-     *
85
-     * An important note: do _not_ create a parent element. Any element
86
-     * implementing XmlSerializble should only ever write what's considered
87
-     * its 'inner xml'.
88
-     *
89
-     * The parent of the current element is responsible for writing a
90
-     * containing element.
91
-     *
92
-     * This allows serializers to be re-used for different element names.
93
-     *
94
-     * If you are opening new elements, you must also close them again.
95
-     *
96
-     * @param Writer $writer
97
-     * @return void
98
-     */
99
-    public function xmlSerialize(Writer $writer) {
100
-
101
-        foreach ($this->privileges as $ace) {
102
-
103
-            $this->serializeAce($writer, $ace);
104
-
105
-        }
106
-
107
-    }
108
-
109
-    /**
110
-     * Generate html representation for this value.
111
-     *
112
-     * The html output is 100% trusted, and no effort is being made to sanitize
113
-     * it. It's up to the implementor to sanitize user provided values.
114
-     *
115
-     * The output must be in UTF-8.
116
-     *
117
-     * The baseUri parameter is a url to the root of the application, and can
118
-     * be used to construct local links.
119
-     *
120
-     * @param HtmlOutputHelper $html
121
-     * @return string
122
-     */
123
-    public function toHtml(HtmlOutputHelper $html) {
124
-
125
-        ob_start();
126
-        echo "<table>";
127
-        echo "<tr><th>Principal</th><th>Privilege</th><th></th></tr>";
128
-        foreach ($this->privileges as $privilege) {
129
-
130
-            echo '<tr>';
131
-            // if it starts with a {, it's a special principal
132
-            if ($privilege['principal'][0] === '{') {
133
-                echo '<td>', $html->xmlName($privilege['principal']), '</td>';
134
-            } else {
135
-                echo '<td>', $html->link($privilege['principal']), '</td>';
136
-            }
137
-            echo '<td>', $html->xmlName($privilege['privilege']), '</td>';
138
-            echo '<td>';
139
-            if (!empty($privilege['protected'])) echo '(protected)';
140
-            echo '</td>';
141
-            echo '</tr>';
142
-
143
-        }
144
-        echo "</table>";
145
-        return ob_get_clean();
146
-
147
-    }
148
-
149
-    /**
150
-     * The deserialize method is called during xml parsing.
151
-     *
152
-     * This method is called statictly, this is because in theory this method
153
-     * may be used as a type of constructor, or factory method.
154
-     *
155
-     * Often you want to return an instance of the current class, but you are
156
-     * free to return other data as well.
157
-     *
158
-     * Important note 2: You are responsible for advancing the reader to the
159
-     * next element. Not doing anything will result in a never-ending loop.
160
-     *
161
-     * If you just want to skip parsing for this element altogether, you can
162
-     * just call $reader->next();
163
-     *
164
-     * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
165
-     * the next element.
166
-     *
167
-     * @param Reader $reader
168
-     * @return mixed
169
-     */
170
-    static function xmlDeserialize(Reader $reader) {
171
-
172
-        $elementMap = [
173
-            '{DAV:}ace'       => 'Sabre\Xml\Element\KeyValue',
174
-            '{DAV:}privilege' => 'Sabre\Xml\Element\Elements',
175
-            '{DAV:}principal' => 'Sabre\DAVACL\Xml\Property\Principal',
176
-        ];
177
-
178
-        $privileges = [];
179
-
180
-        foreach ((array)$reader->parseInnerTree($elementMap) as $element) {
181
-
182
-            if ($element['name'] !== '{DAV:}ace') {
183
-                continue;
184
-            }
185
-            $ace = $element['value'];
186
-
187
-            if (empty($ace['{DAV:}principal'])) {
188
-                throw new DAV\Exception\BadRequest('Each {DAV:}ace element must have one {DAV:}principal element');
189
-            }
190
-            $principal = $ace['{DAV:}principal'];
191
-
192
-            switch ($principal->getType()) {
193
-                case Principal::HREF :
194
-                    $principal = $principal->getHref();
195
-                    break;
196
-                case Principal::AUTHENTICATED :
197
-                    $principal = '{DAV:}authenticated';
198
-                    break;
199
-                case Principal::UNAUTHENTICATED :
200
-                    $principal = '{DAV:}unauthenticated';
201
-                    break;
202
-                case Principal::ALL :
203
-                    $principal = '{DAV:}all';
204
-                    break;
205
-
206
-            }
207
-
208
-            $protected = array_key_exists('{DAV:}protected', $ace);
209
-
210
-            if (!isset($ace['{DAV:}grant'])) {
211
-                throw new DAV\Exception\NotImplemented('Every {DAV:}ace element must have a {DAV:}grant element. {DAV:}deny is not yet supported');
212
-            }
213
-            foreach ($ace['{DAV:}grant'] as $elem) {
214
-                if ($elem['name'] !== '{DAV:}privilege') {
215
-                    continue;
216
-                }
217
-
218
-                foreach ($elem['value'] as $priv) {
219
-                    $privileges[] = [
220
-                        'principal' => $principal,
221
-                        'protected' => $protected,
222
-                        'privilege' => $priv,
223
-                    ];
224
-                }
225
-
226
-            }
227
-
228
-        }
229
-
230
-        return new self($privileges);
231
-
232
-    }
233
-
234
-    /**
235
-     * Serializes a single access control entry.
236
-     *
237
-     * @param Writer $writer
238
-     * @param array $ace
239
-     * @return void
240
-     */
241
-    private function serializeAce(Writer $writer, array $ace) {
242
-
243
-        $writer->startElement('{DAV:}ace');
244
-
245
-        switch ($ace['principal']) {
246
-            case '{DAV:}authenticated' :
247
-                $principal = new Principal(Principal::AUTHENTICATED);
248
-                break;
249
-            case '{DAV:}unauthenticated' :
250
-                $principal = new Principal(Principal::UNAUTHENTICATED);
251
-                break;
252
-            case '{DAV:}all' :
253
-                $principal = new Principal(Principal::ALL);
254
-                break;
255
-            default:
256
-                $principal = new Principal(Principal::HREF, $ace['principal']);
257
-                break;
258
-        }
259
-
260
-        $writer->writeElement('{DAV:}principal', $principal);
261
-        $writer->startElement('{DAV:}grant');
262
-        $writer->startElement('{DAV:}privilege');
263
-
264
-        $writer->writeElement($ace['privilege']);
265
-
266
-        $writer->endElement(); // privilege
267
-        $writer->endElement(); // grant
268
-
269
-        if (!empty($ace['protected'])) {
270
-            $writer->writeElement('{DAV:}protected');
271
-        }
272
-
273
-        $writer->endElement(); // ace
274
-
275
-    }
30
+	/**
31
+	 * List of privileges
32
+	 *
33
+	 * @var array
34
+	 */
35
+	protected $privileges;
36
+
37
+	/**
38
+	 * Whether or not the server base url is required to be prefixed when
39
+	 * serializing the property.
40
+	 *
41
+	 * @var bool
42
+	 */
43
+	protected $prefixBaseUrl;
44
+
45
+	/**
46
+	 * Constructor
47
+	 *
48
+	 * This object requires a structure similar to the return value from
49
+	 * Sabre\DAVACL\Plugin::getACL().
50
+	 *
51
+	 * Each privilege is a an array with at least a 'privilege' property, and a
52
+	 * 'principal' property. A privilege may have a 'protected' property as
53
+	 * well.
54
+	 *
55
+	 * The prefixBaseUrl should be set to false, if the supplied principal urls
56
+	 * are already full urls. If this is kept to true, the servers base url
57
+	 * will automatically be prefixed.
58
+	 *
59
+	 * @param array $privileges
60
+	 * @param bool $prefixBaseUrl
61
+	 */
62
+	public function __construct(array $privileges, $prefixBaseUrl = true) {
63
+
64
+		$this->privileges = $privileges;
65
+		$this->prefixBaseUrl = $prefixBaseUrl;
66
+
67
+	}
68
+
69
+	/**
70
+	 * Returns the list of privileges for this property
71
+	 *
72
+	 * @return array
73
+	 */
74
+	public function getPrivileges() {
75
+
76
+		return $this->privileges;
77
+
78
+	}
79
+
80
+	/**
81
+	 * The xmlSerialize metod is called during xml writing.
82
+	 *
83
+	 * Use the $writer argument to write its own xml serialization.
84
+	 *
85
+	 * An important note: do _not_ create a parent element. Any element
86
+	 * implementing XmlSerializble should only ever write what's considered
87
+	 * its 'inner xml'.
88
+	 *
89
+	 * The parent of the current element is responsible for writing a
90
+	 * containing element.
91
+	 *
92
+	 * This allows serializers to be re-used for different element names.
93
+	 *
94
+	 * If you are opening new elements, you must also close them again.
95
+	 *
96
+	 * @param Writer $writer
97
+	 * @return void
98
+	 */
99
+	public function xmlSerialize(Writer $writer) {
100
+
101
+		foreach ($this->privileges as $ace) {
102
+
103
+			$this->serializeAce($writer, $ace);
104
+
105
+		}
106
+
107
+	}
108
+
109
+	/**
110
+	 * Generate html representation for this value.
111
+	 *
112
+	 * The html output is 100% trusted, and no effort is being made to sanitize
113
+	 * it. It's up to the implementor to sanitize user provided values.
114
+	 *
115
+	 * The output must be in UTF-8.
116
+	 *
117
+	 * The baseUri parameter is a url to the root of the application, and can
118
+	 * be used to construct local links.
119
+	 *
120
+	 * @param HtmlOutputHelper $html
121
+	 * @return string
122
+	 */
123
+	public function toHtml(HtmlOutputHelper $html) {
124
+
125
+		ob_start();
126
+		echo "<table>";
127
+		echo "<tr><th>Principal</th><th>Privilege</th><th></th></tr>";
128
+		foreach ($this->privileges as $privilege) {
129
+
130
+			echo '<tr>';
131
+			// if it starts with a {, it's a special principal
132
+			if ($privilege['principal'][0] === '{') {
133
+				echo '<td>', $html->xmlName($privilege['principal']), '</td>';
134
+			} else {
135
+				echo '<td>', $html->link($privilege['principal']), '</td>';
136
+			}
137
+			echo '<td>', $html->xmlName($privilege['privilege']), '</td>';
138
+			echo '<td>';
139
+			if (!empty($privilege['protected'])) echo '(protected)';
140
+			echo '</td>';
141
+			echo '</tr>';
142
+
143
+		}
144
+		echo "</table>";
145
+		return ob_get_clean();
146
+
147
+	}
148
+
149
+	/**
150
+	 * The deserialize method is called during xml parsing.
151
+	 *
152
+	 * This method is called statictly, this is because in theory this method
153
+	 * may be used as a type of constructor, or factory method.
154
+	 *
155
+	 * Often you want to return an instance of the current class, but you are
156
+	 * free to return other data as well.
157
+	 *
158
+	 * Important note 2: You are responsible for advancing the reader to the
159
+	 * next element. Not doing anything will result in a never-ending loop.
160
+	 *
161
+	 * If you just want to skip parsing for this element altogether, you can
162
+	 * just call $reader->next();
163
+	 *
164
+	 * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
165
+	 * the next element.
166
+	 *
167
+	 * @param Reader $reader
168
+	 * @return mixed
169
+	 */
170
+	static function xmlDeserialize(Reader $reader) {
171
+
172
+		$elementMap = [
173
+			'{DAV:}ace'       => 'Sabre\Xml\Element\KeyValue',
174
+			'{DAV:}privilege' => 'Sabre\Xml\Element\Elements',
175
+			'{DAV:}principal' => 'Sabre\DAVACL\Xml\Property\Principal',
176
+		];
177
+
178
+		$privileges = [];
179
+
180
+		foreach ((array)$reader->parseInnerTree($elementMap) as $element) {
181
+
182
+			if ($element['name'] !== '{DAV:}ace') {
183
+				continue;
184
+			}
185
+			$ace = $element['value'];
186
+
187
+			if (empty($ace['{DAV:}principal'])) {
188
+				throw new DAV\Exception\BadRequest('Each {DAV:}ace element must have one {DAV:}principal element');
189
+			}
190
+			$principal = $ace['{DAV:}principal'];
191
+
192
+			switch ($principal->getType()) {
193
+				case Principal::HREF :
194
+					$principal = $principal->getHref();
195
+					break;
196
+				case Principal::AUTHENTICATED :
197
+					$principal = '{DAV:}authenticated';
198
+					break;
199
+				case Principal::UNAUTHENTICATED :
200
+					$principal = '{DAV:}unauthenticated';
201
+					break;
202
+				case Principal::ALL :
203
+					$principal = '{DAV:}all';
204
+					break;
205
+
206
+			}
207
+
208
+			$protected = array_key_exists('{DAV:}protected', $ace);
209
+
210
+			if (!isset($ace['{DAV:}grant'])) {
211
+				throw new DAV\Exception\NotImplemented('Every {DAV:}ace element must have a {DAV:}grant element. {DAV:}deny is not yet supported');
212
+			}
213
+			foreach ($ace['{DAV:}grant'] as $elem) {
214
+				if ($elem['name'] !== '{DAV:}privilege') {
215
+					continue;
216
+				}
217
+
218
+				foreach ($elem['value'] as $priv) {
219
+					$privileges[] = [
220
+						'principal' => $principal,
221
+						'protected' => $protected,
222
+						'privilege' => $priv,
223
+					];
224
+				}
225
+
226
+			}
227
+
228
+		}
229
+
230
+		return new self($privileges);
231
+
232
+	}
233
+
234
+	/**
235
+	 * Serializes a single access control entry.
236
+	 *
237
+	 * @param Writer $writer
238
+	 * @param array $ace
239
+	 * @return void
240
+	 */
241
+	private function serializeAce(Writer $writer, array $ace) {
242
+
243
+		$writer->startElement('{DAV:}ace');
244
+
245
+		switch ($ace['principal']) {
246
+			case '{DAV:}authenticated' :
247
+				$principal = new Principal(Principal::AUTHENTICATED);
248
+				break;
249
+			case '{DAV:}unauthenticated' :
250
+				$principal = new Principal(Principal::UNAUTHENTICATED);
251
+				break;
252
+			case '{DAV:}all' :
253
+				$principal = new Principal(Principal::ALL);
254
+				break;
255
+			default:
256
+				$principal = new Principal(Principal::HREF, $ace['principal']);
257
+				break;
258
+		}
259
+
260
+		$writer->writeElement('{DAV:}principal', $principal);
261
+		$writer->startElement('{DAV:}grant');
262
+		$writer->startElement('{DAV:}privilege');
263
+
264
+		$writer->writeElement($ace['privilege']);
265
+
266
+		$writer->endElement(); // privilege
267
+		$writer->endElement(); // grant
268
+
269
+		if (!empty($ace['protected'])) {
270
+			$writer->writeElement('{DAV:}protected');
271
+		}
272
+
273
+		$writer->endElement(); // ace
274
+
275
+	}
276 276
 
277 277
 }
Please login to merge, or discard this patch.
libraries/SabreDAV/DAVACL/Xml/Property/CurrentUserPrivilegeSet.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -115,7 +115,7 @@
 block discarded – undo
115 115
      * the next element.
116 116
      *
117 117
      * @param Reader $reader
118
-     * @return mixed
118
+     * @return CurrentUserPrivilegeSet
119 119
      */
120 120
     static function xmlDeserialize(Reader $reader) {
121 121
 
Please login to merge, or discard this patch.
Indentation   +134 added lines, -134 removed lines patch added patch discarded remove patch
@@ -20,140 +20,140 @@
 block discarded – undo
20 20
  */
21 21
 class CurrentUserPrivilegeSet implements Element, HtmlOutput {
22 22
 
23
-    /**
24
-     * List of privileges
25
-     *
26
-     * @var array
27
-     */
28
-    private $privileges;
29
-
30
-    /**
31
-     * Creates the object
32
-     *
33
-     * Pass the privileges in clark-notation
34
-     *
35
-     * @param array $privileges
36
-     */
37
-    public function __construct(array $privileges) {
38
-
39
-        $this->privileges = $privileges;
40
-
41
-    }
42
-
43
-    /**
44
-     * The xmlSerialize metod is called during xml writing.
45
-     *
46
-     * Use the $writer argument to write its own xml serialization.
47
-     *
48
-     * An important note: do _not_ create a parent element. Any element
49
-     * implementing XmlSerializble should only ever write what's considered
50
-     * its 'inner xml'.
51
-     *
52
-     * The parent of the current element is responsible for writing a
53
-     * containing element.
54
-     *
55
-     * This allows serializers to be re-used for different element names.
56
-     *
57
-     * If you are opening new elements, you must also close them again.
58
-     *
59
-     * @param Writer $writer
60
-     * @return void
61
-     */
62
-    public function xmlSerialize(Writer $writer) {
63
-
64
-        foreach ($this->privileges as $privName) {
65
-
66
-            $writer->startElement('{DAV:}privilege');
67
-            $writer->writeElement($privName);
68
-            $writer->endElement();
69
-
70
-        }
71
-
72
-
73
-    }
74
-
75
-    /**
76
-     * Returns true or false, whether the specified principal appears in the
77
-     * list.
78
-     *
79
-     * @param string $privilegeName
80
-     * @return bool
81
-     */
82
-    public function has($privilegeName) {
83
-
84
-        return in_array($privilegeName, $this->privileges);
85
-
86
-    }
87
-
88
-    /**
89
-     * Returns the list of privileges.
90
-     *
91
-     * @return array
92
-     */
93
-    public function getValue() {
94
-
95
-        return $this->privileges;
96
-
97
-    }
98
-
99
-    /**
100
-     * The deserialize method is called during xml parsing.
101
-     *
102
-     * This method is called statictly, this is because in theory this method
103
-     * may be used as a type of constructor, or factory method.
104
-     *
105
-     * Often you want to return an instance of the current class, but you are
106
-     * free to return other data as well.
107
-     *
108
-     * You are responsible for advancing the reader to the next element. Not
109
-     * doing anything will result in a never-ending loop.
110
-     *
111
-     * If you just want to skip parsing for this element altogether, you can
112
-     * just call $reader->next();
113
-     *
114
-     * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
115
-     * the next element.
116
-     *
117
-     * @param Reader $reader
118
-     * @return mixed
119
-     */
120
-    static function xmlDeserialize(Reader $reader) {
121
-
122
-        $result = [];
123
-
124
-        $tree = $reader->parseInnerTree(['{DAV:}privilege' => 'Sabre\\Xml\\Element\\Elements']);
125
-        foreach ($tree as $element) {
126
-            if ($element['name'] !== '{DAV:}privilege') {
127
-                continue;
128
-            }
129
-            $result[] = $element['value'][0];
130
-        }
131
-        return new self($result);
132
-
133
-    }
134
-
135
-    /**
136
-     * Generate html representation for this value.
137
-     *
138
-     * The html output is 100% trusted, and no effort is being made to sanitize
139
-     * it. It's up to the implementor to sanitize user provided values.
140
-     *
141
-     * The output must be in UTF-8.
142
-     *
143
-     * The baseUri parameter is a url to the root of the application, and can
144
-     * be used to construct local links.
145
-     *
146
-     * @param HtmlOutputHelper $html
147
-     * @return string
148
-     */
149
-    public function toHtml(HtmlOutputHelper $html) {
150
-
151
-        return implode(
152
-            ', ',
153
-            array_map([$html, 'xmlName'], $this->getValue())
154
-        );
155
-
156
-    }
23
+	/**
24
+	 * List of privileges
25
+	 *
26
+	 * @var array
27
+	 */
28
+	private $privileges;
29
+
30
+	/**
31
+	 * Creates the object
32
+	 *
33
+	 * Pass the privileges in clark-notation
34
+	 *
35
+	 * @param array $privileges
36
+	 */
37
+	public function __construct(array $privileges) {
38
+
39
+		$this->privileges = $privileges;
40
+
41
+	}
42
+
43
+	/**
44
+	 * The xmlSerialize metod is called during xml writing.
45
+	 *
46
+	 * Use the $writer argument to write its own xml serialization.
47
+	 *
48
+	 * An important note: do _not_ create a parent element. Any element
49
+	 * implementing XmlSerializble should only ever write what's considered
50
+	 * its 'inner xml'.
51
+	 *
52
+	 * The parent of the current element is responsible for writing a
53
+	 * containing element.
54
+	 *
55
+	 * This allows serializers to be re-used for different element names.
56
+	 *
57
+	 * If you are opening new elements, you must also close them again.
58
+	 *
59
+	 * @param Writer $writer
60
+	 * @return void
61
+	 */
62
+	public function xmlSerialize(Writer $writer) {
63
+
64
+		foreach ($this->privileges as $privName) {
65
+
66
+			$writer->startElement('{DAV:}privilege');
67
+			$writer->writeElement($privName);
68
+			$writer->endElement();
69
+
70
+		}
71
+
72
+
73
+	}
74
+
75
+	/**
76
+	 * Returns true or false, whether the specified principal appears in the
77
+	 * list.
78
+	 *
79
+	 * @param string $privilegeName
80
+	 * @return bool
81
+	 */
82
+	public function has($privilegeName) {
83
+
84
+		return in_array($privilegeName, $this->privileges);
85
+
86
+	}
87
+
88
+	/**
89
+	 * Returns the list of privileges.
90
+	 *
91
+	 * @return array
92
+	 */
93
+	public function getValue() {
94
+
95
+		return $this->privileges;
96
+
97
+	}
98
+
99
+	/**
100
+	 * The deserialize method is called during xml parsing.
101
+	 *
102
+	 * This method is called statictly, this is because in theory this method
103
+	 * may be used as a type of constructor, or factory method.
104
+	 *
105
+	 * Often you want to return an instance of the current class, but you are
106
+	 * free to return other data as well.
107
+	 *
108
+	 * You are responsible for advancing the reader to the next element. Not
109
+	 * doing anything will result in a never-ending loop.
110
+	 *
111
+	 * If you just want to skip parsing for this element altogether, you can
112
+	 * just call $reader->next();
113
+	 *
114
+	 * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
115
+	 * the next element.
116
+	 *
117
+	 * @param Reader $reader
118
+	 * @return mixed
119
+	 */
120
+	static function xmlDeserialize(Reader $reader) {
121
+
122
+		$result = [];
123
+
124
+		$tree = $reader->parseInnerTree(['{DAV:}privilege' => 'Sabre\\Xml\\Element\\Elements']);
125
+		foreach ($tree as $element) {
126
+			if ($element['name'] !== '{DAV:}privilege') {
127
+				continue;
128
+			}
129
+			$result[] = $element['value'][0];
130
+		}
131
+		return new self($result);
132
+
133
+	}
134
+
135
+	/**
136
+	 * Generate html representation for this value.
137
+	 *
138
+	 * The html output is 100% trusted, and no effort is being made to sanitize
139
+	 * it. It's up to the implementor to sanitize user provided values.
140
+	 *
141
+	 * The output must be in UTF-8.
142
+	 *
143
+	 * The baseUri parameter is a url to the root of the application, and can
144
+	 * be used to construct local links.
145
+	 *
146
+	 * @param HtmlOutputHelper $html
147
+	 * @return string
148
+	 */
149
+	public function toHtml(HtmlOutputHelper $html) {
150
+
151
+		return implode(
152
+			', ',
153
+			array_map([$html, 'xmlName'], $this->getValue())
154
+		);
155
+
156
+	}
157 157
 
158 158
 
159 159
 }
Please login to merge, or discard this patch.
libraries/SabreDAV/DAVACL/Xml/Property/Principal.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -172,7 +172,7 @@
 block discarded – undo
172 172
      * the next element.
173 173
      *
174 174
      * @param Reader $reader
175
-     * @return mixed
175
+     * @return Principal
176 176
      */
177 177
     static function xmlDeserialize(Reader $reader) {
178 178
 
Please login to merge, or discard this patch.
Indentation   +172 added lines, -172 removed lines patch added patch discarded remove patch
@@ -20,177 +20,177 @@
 block discarded – undo
20 20
  */
21 21
 class Principal extends DAV\Xml\Property\Href {
22 22
 
23
-    /**
24
-     * To specify a not-logged-in user, use the UNAUTHENTICATED principal
25
-     */
26
-    const UNAUTHENTICATED = 1;
27
-
28
-    /**
29
-     * To specify any principal that is logged in, use AUTHENTICATED
30
-     */
31
-    const AUTHENTICATED = 2;
32
-
33
-    /**
34
-     * Specific principals can be specified with the HREF
35
-     */
36
-    const HREF = 3;
37
-
38
-    /**
39
-     * Everybody, basically
40
-     */
41
-    const ALL = 4;
42
-
43
-    /**
44
-     * Principal-type
45
-     *
46
-     * Must be one of the UNAUTHENTICATED, AUTHENTICATED or HREF constants.
47
-     *
48
-     * @var int
49
-     */
50
-    protected $type;
51
-
52
-    /**
53
-     * Creates the property.
54
-     *
55
-     * The 'type' argument must be one of the type constants defined in this class.
56
-     *
57
-     * 'href' is only required for the HREF type.
58
-     *
59
-     * @param int $type
60
-     * @param string|null $href
61
-     */
62
-    public function __construct($type, $href = null) {
63
-
64
-        $this->type = $type;
65
-        if ($type === self::HREF && is_null($href)) {
66
-            throw new DAV\Exception('The href argument must be specified for the HREF principal type.');
67
-        }
68
-        if ($href) {
69
-            $href = rtrim($href, '/') . '/';
70
-            parent::__construct($href);
71
-        }
72
-
73
-    }
74
-
75
-    /**
76
-     * Returns the principal type
77
-     *
78
-     * @return int
79
-     */
80
-    public function getType() {
81
-
82
-        return $this->type;
83
-
84
-    }
85
-
86
-
87
-    /**
88
-     * The xmlSerialize metod is called during xml writing.
89
-     *
90
-     * Use the $writer argument to write its own xml serialization.
91
-     *
92
-     * An important note: do _not_ create a parent element. Any element
93
-     * implementing XmlSerializble should only ever write what's considered
94
-     * its 'inner xml'.
95
-     *
96
-     * The parent of the current element is responsible for writing a
97
-     * containing element.
98
-     *
99
-     * This allows serializers to be re-used for different element names.
100
-     *
101
-     * If you are opening new elements, you must also close them again.
102
-     *
103
-     * @param Writer $writer
104
-     * @return void
105
-     */
106
-    public function xmlSerialize(Writer $writer) {
107
-
108
-        switch ($this->type) {
109
-
110
-            case self::UNAUTHENTICATED :
111
-                $writer->writeElement('{DAV:}unauthenticated');
112
-                break;
113
-            case self::AUTHENTICATED :
114
-                $writer->writeElement('{DAV:}authenticated');
115
-                break;
116
-            case self::HREF :
117
-                parent::xmlSerialize($writer);
118
-                break;
119
-            case self::ALL :
120
-                $writer->writeElement('{DAV:}all');
121
-                break;
122
-        }
123
-
124
-    }
125
-
126
-    /**
127
-     * Generate html representation for this value.
128
-     *
129
-     * The html output is 100% trusted, and no effort is being made to sanitize
130
-     * it. It's up to the implementor to sanitize user provided values.
131
-     *
132
-     * The output must be in UTF-8.
133
-     *
134
-     * The baseUri parameter is a url to the root of the application, and can
135
-     * be used to construct local links.
136
-     *
137
-     * @param HtmlOutputHelper $html
138
-     * @return string
139
-     */
140
-    public function toHtml(HtmlOutputHelper $html) {
141
-
142
-        switch ($this->type) {
143
-
144
-            case self::UNAUTHENTICATED :
145
-                return '<em>unauthenticated</em>';
146
-            case self::AUTHENTICATED :
147
-                return '<em>authenticated</em>';
148
-            case self::HREF :
149
-                return parent::toHtml($html);
150
-            case self::ALL :
151
-                return '<em>all</em>';
152
-        }
153
-
154
-    }
155
-
156
-    /**
157
-     * The deserialize method is called during xml parsing.
158
-     *
159
-     * This method is called staticly, this is because in theory this method
160
-     * may be used as a type of constructor, or factory method.
161
-     *
162
-     * Often you want to return an instance of the current class, but you are
163
-     * free to return other data as well.
164
-     *
165
-     * Important note 2: You are responsible for advancing the reader to the
166
-     * next element. Not doing anything will result in a never-ending loop.
167
-     *
168
-     * If you just want to skip parsing for this element altogether, you can
169
-     * just call $reader->next();
170
-     *
171
-     * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
172
-     * the next element.
173
-     *
174
-     * @param Reader $reader
175
-     * @return mixed
176
-     */
177
-    static function xmlDeserialize(Reader $reader) {
178
-
179
-        $tree = $reader->parseInnerTree()[0];
180
-
181
-        switch ($tree['name']) {
182
-            case '{DAV:}unauthenticated' :
183
-                return new self(self::UNAUTHENTICATED);
184
-            case '{DAV:}authenticated' :
185
-                return new self(self::AUTHENTICATED);
186
-            case '{DAV:}href':
187
-                return new self(self::HREF, $tree['value']);
188
-            case '{DAV:}all':
189
-                return new self(self::ALL);
190
-            default :
191
-                throw new BadRequest('Unknown or unsupported principal type: ' . $tree['name']);
192
-        }
193
-
194
-    }
23
+	/**
24
+	 * To specify a not-logged-in user, use the UNAUTHENTICATED principal
25
+	 */
26
+	const UNAUTHENTICATED = 1;
27
+
28
+	/**
29
+	 * To specify any principal that is logged in, use AUTHENTICATED
30
+	 */
31
+	const AUTHENTICATED = 2;
32
+
33
+	/**
34
+	 * Specific principals can be specified with the HREF
35
+	 */
36
+	const HREF = 3;
37
+
38
+	/**
39
+	 * Everybody, basically
40
+	 */
41
+	const ALL = 4;
42
+
43
+	/**
44
+	 * Principal-type
45
+	 *
46
+	 * Must be one of the UNAUTHENTICATED, AUTHENTICATED or HREF constants.
47
+	 *
48
+	 * @var int
49
+	 */
50
+	protected $type;
51
+
52
+	/**
53
+	 * Creates the property.
54
+	 *
55
+	 * The 'type' argument must be one of the type constants defined in this class.
56
+	 *
57
+	 * 'href' is only required for the HREF type.
58
+	 *
59
+	 * @param int $type
60
+	 * @param string|null $href
61
+	 */
62
+	public function __construct($type, $href = null) {
63
+
64
+		$this->type = $type;
65
+		if ($type === self::HREF && is_null($href)) {
66
+			throw new DAV\Exception('The href argument must be specified for the HREF principal type.');
67
+		}
68
+		if ($href) {
69
+			$href = rtrim($href, '/') . '/';
70
+			parent::__construct($href);
71
+		}
72
+
73
+	}
74
+
75
+	/**
76
+	 * Returns the principal type
77
+	 *
78
+	 * @return int
79
+	 */
80
+	public function getType() {
81
+
82
+		return $this->type;
83
+
84
+	}
85
+
86
+
87
+	/**
88
+	 * The xmlSerialize metod is called during xml writing.
89
+	 *
90
+	 * Use the $writer argument to write its own xml serialization.
91
+	 *
92
+	 * An important note: do _not_ create a parent element. Any element
93
+	 * implementing XmlSerializble should only ever write what's considered
94
+	 * its 'inner xml'.
95
+	 *
96
+	 * The parent of the current element is responsible for writing a
97
+	 * containing element.
98
+	 *
99
+	 * This allows serializers to be re-used for different element names.
100
+	 *
101
+	 * If you are opening new elements, you must also close them again.
102
+	 *
103
+	 * @param Writer $writer
104
+	 * @return void
105
+	 */
106
+	public function xmlSerialize(Writer $writer) {
107
+
108
+		switch ($this->type) {
109
+
110
+			case self::UNAUTHENTICATED :
111
+				$writer->writeElement('{DAV:}unauthenticated');
112
+				break;
113
+			case self::AUTHENTICATED :
114
+				$writer->writeElement('{DAV:}authenticated');
115
+				break;
116
+			case self::HREF :
117
+				parent::xmlSerialize($writer);
118
+				break;
119
+			case self::ALL :
120
+				$writer->writeElement('{DAV:}all');
121
+				break;
122
+		}
123
+
124
+	}
125
+
126
+	/**
127
+	 * Generate html representation for this value.
128
+	 *
129
+	 * The html output is 100% trusted, and no effort is being made to sanitize
130
+	 * it. It's up to the implementor to sanitize user provided values.
131
+	 *
132
+	 * The output must be in UTF-8.
133
+	 *
134
+	 * The baseUri parameter is a url to the root of the application, and can
135
+	 * be used to construct local links.
136
+	 *
137
+	 * @param HtmlOutputHelper $html
138
+	 * @return string
139
+	 */
140
+	public function toHtml(HtmlOutputHelper $html) {
141
+
142
+		switch ($this->type) {
143
+
144
+			case self::UNAUTHENTICATED :
145
+				return '<em>unauthenticated</em>';
146
+			case self::AUTHENTICATED :
147
+				return '<em>authenticated</em>';
148
+			case self::HREF :
149
+				return parent::toHtml($html);
150
+			case self::ALL :
151
+				return '<em>all</em>';
152
+		}
153
+
154
+	}
155
+
156
+	/**
157
+	 * The deserialize method is called during xml parsing.
158
+	 *
159
+	 * This method is called staticly, this is because in theory this method
160
+	 * may be used as a type of constructor, or factory method.
161
+	 *
162
+	 * Often you want to return an instance of the current class, but you are
163
+	 * free to return other data as well.
164
+	 *
165
+	 * Important note 2: You are responsible for advancing the reader to the
166
+	 * next element. Not doing anything will result in a never-ending loop.
167
+	 *
168
+	 * If you just want to skip parsing for this element altogether, you can
169
+	 * just call $reader->next();
170
+	 *
171
+	 * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
172
+	 * the next element.
173
+	 *
174
+	 * @param Reader $reader
175
+	 * @return mixed
176
+	 */
177
+	static function xmlDeserialize(Reader $reader) {
178
+
179
+		$tree = $reader->parseInnerTree()[0];
180
+
181
+		switch ($tree['name']) {
182
+			case '{DAV:}unauthenticated' :
183
+				return new self(self::UNAUTHENTICATED);
184
+			case '{DAV:}authenticated' :
185
+				return new self(self::AUTHENTICATED);
186
+			case '{DAV:}href':
187
+				return new self(self::HREF, $tree['value']);
188
+			case '{DAV:}all':
189
+				return new self(self::ALL);
190
+			default :
191
+				throw new BadRequest('Unknown or unsupported principal type: ' . $tree['name']);
192
+		}
193
+
194
+	}
195 195
 
196 196
 }
Please login to merge, or discard this patch.
libraries/SabreDAV/DAVACL/Xml/Request/ExpandPropertyReport.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@
 block discarded – undo
51 51
      * the next element.
52 52
      *
53 53
      * @param Reader $reader
54
-     * @return mixed
54
+     * @return ExpandPropertyReport
55 55
      */
56 56
     static function xmlDeserialize(Reader $reader) {
57 57
 
Please login to merge, or discard this patch.
Indentation   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -18,86 +18,86 @@
 block discarded – undo
18 18
  */
19 19
 class ExpandPropertyReport implements XmlDeserializable {
20 20
 
21
-    /**
22
-     * An array with requested properties.
23
-     *
24
-     * The requested properties will be used as keys in this array. The value
25
-     * is normally null.
26
-     *
27
-     * If the value is an array though, it means the property must be expanded.
28
-     * Within the array, the sub-properties, which themselves may be null or
29
-     * arrays.
30
-     *
31
-     * @var array
32
-     */
33
-    public $properties;
34
-
35
-    /**
36
-     * The deserialize method is called during xml parsing.
37
-     *
38
-     * This method is called statictly, 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
-     * @param Reader $reader
54
-     * @return mixed
55
-     */
56
-    static function xmlDeserialize(Reader $reader) {
57
-
58
-        $elems = $reader->parseInnerTree();
59
-
60
-        $obj = new self();
61
-        $obj->properties = self::traverse($elems);
62
-
63
-        return $obj;
64
-
65
-    }
66
-
67
-    /**
68
-     * This method is used by deserializeXml, to recursively parse the
69
-     * {DAV:}property elements.
70
-     *
71
-     * @param array $elems
72
-     * @return void
73
-     */
74
-    private static function traverse($elems) {
75
-
76
-        $result = [];
77
-
78
-        foreach ($elems as $elem) {
79
-
80
-            if ($elem['name'] !== '{DAV:}property') {
81
-                continue;
82
-            }
83
-
84
-            $namespace = isset($elem['attributes']['namespace']) ?
85
-                $elem['attributes']['namespace'] :
86
-                'DAV:';
87
-
88
-            $propName = '{' . $namespace . '}' . $elem['attributes']['name'];
89
-
90
-            $value = null;
91
-            if (is_array($elem['value'])) {
92
-                $value = self::traverse($elem['value']);
93
-            }
94
-
95
-            $result[$propName] = $value;
96
-
97
-        }
98
-
99
-        return $result;
100
-
101
-    }
21
+	/**
22
+	 * An array with requested properties.
23
+	 *
24
+	 * The requested properties will be used as keys in this array. The value
25
+	 * is normally null.
26
+	 *
27
+	 * If the value is an array though, it means the property must be expanded.
28
+	 * Within the array, the sub-properties, which themselves may be null or
29
+	 * arrays.
30
+	 *
31
+	 * @var array
32
+	 */
33
+	public $properties;
34
+
35
+	/**
36
+	 * The deserialize method is called during xml parsing.
37
+	 *
38
+	 * This method is called statictly, 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
+	 * @param Reader $reader
54
+	 * @return mixed
55
+	 */
56
+	static function xmlDeserialize(Reader $reader) {
57
+
58
+		$elems = $reader->parseInnerTree();
59
+
60
+		$obj = new self();
61
+		$obj->properties = self::traverse($elems);
62
+
63
+		return $obj;
64
+
65
+	}
66
+
67
+	/**
68
+	 * This method is used by deserializeXml, to recursively parse the
69
+	 * {DAV:}property elements.
70
+	 *
71
+	 * @param array $elems
72
+	 * @return void
73
+	 */
74
+	private static function traverse($elems) {
75
+
76
+		$result = [];
77
+
78
+		foreach ($elems as $elem) {
79
+
80
+			if ($elem['name'] !== '{DAV:}property') {
81
+				continue;
82
+			}
83
+
84
+			$namespace = isset($elem['attributes']['namespace']) ?
85
+				$elem['attributes']['namespace'] :
86
+				'DAV:';
87
+
88
+			$propName = '{' . $namespace . '}' . $elem['attributes']['name'];
89
+
90
+			$value = null;
91
+			if (is_array($elem['value'])) {
92
+				$value = self::traverse($elem['value']);
93
+			}
94
+
95
+			$result[$propName] = $value;
96
+
97
+		}
98
+
99
+		return $result;
100
+
101
+	}
102 102
 
103 103
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -82,8 +82,7 @@
 block discarded – undo
82 82
             }
83 83
 
84 84
             $namespace = isset($elem['attributes']['namespace']) ?
85
-                $elem['attributes']['namespace'] :
86
-                'DAV:';
85
+                $elem['attributes']['namespace'] : 'DAV:';
87 86
 
88 87
             $propName = '{' . $namespace . '}' . $elem['attributes']['name'];
89 88
 
Please login to merge, or discard this patch.
libraries/SabreDAV/DAVACL/Xml/Request/PrincipalPropertySearchReport.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -72,7 +72,7 @@
 block discarded – undo
72 72
      * the next element.
73 73
      *
74 74
      * @param Reader $reader
75
-     * @return mixed
75
+     * @return PrincipalPropertySearchReport
76 76
      */
77 77
     static function xmlDeserialize(Reader $reader) {
78 78
 
Please login to merge, or discard this patch.
Indentation   +102 added lines, -102 removed lines patch added patch discarded remove patch
@@ -20,108 +20,108 @@
 block discarded – undo
20 20
  */
21 21
 class PrincipalPropertySearchReport implements XmlDeserializable {
22 22
 
23
-    /**
24
-     * The requested properties.
25
-     *
26
-     * @var array|null
27
-     */
28
-    public $properties;
29
-
30
-    /**
31
-     * searchProperties
32
-     *
33
-     * @var array
34
-     */
35
-    public $searchProperties = [];
36
-
37
-    /**
38
-     * By default the property search will be conducted on the url of the http
39
-     * request. If this is set to true, it will be applied to the principal
40
-     * collection set instead.
41
-     *
42
-     * @var bool
43
-     */
44
-    public $applyToPrincipalCollectionSet = false;
45
-
46
-    /**
47
-     * Search for principals matching ANY of the properties (OR) or a ALL of
48
-     * the properties (AND).
49
-     *
50
-     * This property is either "anyof" or "allof".
51
-     *
52
-     * @var string
53
-     */
54
-    public $test;
55
-
56
-    /**
57
-     * The deserialize method is called during xml parsing.
58
-     *
59
-     * This method is called statictly, this is because in theory this method
60
-     * may be used as a type of constructor, or factory method.
61
-     *
62
-     * Often you want to return an instance of the current class, but you are
63
-     * free to return other data as well.
64
-     *
65
-     * You are responsible for advancing the reader to the next element. Not
66
-     * doing anything will result in a never-ending loop.
67
-     *
68
-     * If you just want to skip parsing for this element altogether, you can
69
-     * just call $reader->next();
70
-     *
71
-     * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
72
-     * the next element.
73
-     *
74
-     * @param Reader $reader
75
-     * @return mixed
76
-     */
77
-    static function xmlDeserialize(Reader $reader) {
78
-
79
-        $self = new self();
80
-
81
-        $foundSearchProp = false;
82
-        $self->test = 'allof';
83
-        if ($reader->getAttribute('test') === 'anyof') {
84
-            $self->test = 'anyof';
85
-        }
86
-
87
-        $elemMap = [
88
-            '{DAV:}property-search' => 'Sabre\\Xml\\Element\\KeyValue',
89
-            '{DAV:}prop'            => 'Sabre\\Xml\\Element\\KeyValue',
90
-        ];
23
+	/**
24
+	 * The requested properties.
25
+	 *
26
+	 * @var array|null
27
+	 */
28
+	public $properties;
29
+
30
+	/**
31
+	 * searchProperties
32
+	 *
33
+	 * @var array
34
+	 */
35
+	public $searchProperties = [];
36
+
37
+	/**
38
+	 * By default the property search will be conducted on the url of the http
39
+	 * request. If this is set to true, it will be applied to the principal
40
+	 * collection set instead.
41
+	 *
42
+	 * @var bool
43
+	 */
44
+	public $applyToPrincipalCollectionSet = false;
45
+
46
+	/**
47
+	 * Search for principals matching ANY of the properties (OR) or a ALL of
48
+	 * the properties (AND).
49
+	 *
50
+	 * This property is either "anyof" or "allof".
51
+	 *
52
+	 * @var string
53
+	 */
54
+	public $test;
55
+
56
+	/**
57
+	 * The deserialize method is called during xml parsing.
58
+	 *
59
+	 * This method is called statictly, this is because in theory this method
60
+	 * may be used as a type of constructor, or factory method.
61
+	 *
62
+	 * Often you want to return an instance of the current class, but you are
63
+	 * free to return other data as well.
64
+	 *
65
+	 * You are responsible for advancing the reader to the next element. Not
66
+	 * doing anything will result in a never-ending loop.
67
+	 *
68
+	 * If you just want to skip parsing for this element altogether, you can
69
+	 * just call $reader->next();
70
+	 *
71
+	 * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
72
+	 * the next element.
73
+	 *
74
+	 * @param Reader $reader
75
+	 * @return mixed
76
+	 */
77
+	static function xmlDeserialize(Reader $reader) {
78
+
79
+		$self = new self();
80
+
81
+		$foundSearchProp = false;
82
+		$self->test = 'allof';
83
+		if ($reader->getAttribute('test') === 'anyof') {
84
+			$self->test = 'anyof';
85
+		}
86
+
87
+		$elemMap = [
88
+			'{DAV:}property-search' => 'Sabre\\Xml\\Element\\KeyValue',
89
+			'{DAV:}prop'            => 'Sabre\\Xml\\Element\\KeyValue',
90
+		];
91 91
         
92
-        foreach ($reader->parseInnerTree($elemMap) as $elem) {
93
-
94
-            switch ($elem['name']) {
95
-
96
-                case '{DAV:}prop' :
97
-                    $self->properties = array_keys($elem['value']);
98
-                    break;
99
-                case '{DAV:}property-search' :
100
-                    $foundSearchProp = true;
101
-                    // This property has two sub-elements:
102
-                    //   {DAV:}prop - The property to be searched on. This may
103
-                    //                also be more than one
104
-                    //   {DAV:}match - The value to match with
105
-                    if (!isset($elem['value']['{DAV:}prop']) || !isset($elem['value']['{DAV:}match'])) {
106
-                        throw new BadRequest('The {DAV:}property-search element must contain one {DAV:}match and one {DAV:}prop element');
107
-                    }
108
-                    foreach ($elem['value']['{DAV:}prop'] as $propName => $discard) {
109
-                        $self->searchProperties[$propName] = $elem['value']['{DAV:}match'];
110
-                    }
111
-                    break;
112
-                case '{DAV:}apply-to-principal-collection-set' :
113
-                    $self->applyToPrincipalCollectionSet = true;
114
-                    break;
115
-
116
-            }
117
-
118
-        }
119
-        if (!$foundSearchProp) {
120
-            throw new BadRequest('The {DAV:}principal-property-search report must contain at least 1 {DAV:}property-search element');
121
-        }
122
-
123
-        return $self;
124
-
125
-    }
92
+		foreach ($reader->parseInnerTree($elemMap) as $elem) {
93
+
94
+			switch ($elem['name']) {
95
+
96
+				case '{DAV:}prop' :
97
+					$self->properties = array_keys($elem['value']);
98
+					break;
99
+				case '{DAV:}property-search' :
100
+					$foundSearchProp = true;
101
+					// This property has two sub-elements:
102
+					//   {DAV:}prop - The property to be searched on. This may
103
+					//                also be more than one
104
+					//   {DAV:}match - The value to match with
105
+					if (!isset($elem['value']['{DAV:}prop']) || !isset($elem['value']['{DAV:}match'])) {
106
+						throw new BadRequest('The {DAV:}property-search element must contain one {DAV:}match and one {DAV:}prop element');
107
+					}
108
+					foreach ($elem['value']['{DAV:}prop'] as $propName => $discard) {
109
+						$self->searchProperties[$propName] = $elem['value']['{DAV:}match'];
110
+					}
111
+					break;
112
+				case '{DAV:}apply-to-principal-collection-set' :
113
+					$self->applyToPrincipalCollectionSet = true;
114
+					break;
115
+
116
+			}
117
+
118
+		}
119
+		if (!$foundSearchProp) {
120
+			throw new BadRequest('The {DAV:}principal-property-search report must contain at least 1 {DAV:}property-search element');
121
+		}
122
+
123
+		return $self;
124
+
125
+	}
126 126
 
127 127
 }
Please login to merge, or discard this patch.
Unused Use Statements   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -2,9 +2,9 @@
 block discarded – undo
2 2
 
3 3
 namespace Sabre\DAVACL\Xml\Request;
4 4
 
5
+use Sabre\DAV\Exception\BadRequest;
5 6
 use Sabre\Xml\Reader;
6 7
 use Sabre\Xml\XmlDeserializable;
7
-use Sabre\DAV\Exception\BadRequest;
8 8
 
9 9
 /**
10 10
  * PrincipalSearchPropertySetReport request parser.
Please login to merge, or discard this patch.
libraries/SabreDAV/DAVACL/Xml/Request/PrincipalSearchPropertySetReport.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@
 block discarded – undo
39 39
      * the next element.
40 40
      *
41 41
      * @param Reader $reader
42
-     * @return mixed
42
+     * @return PrincipalSearchPropertySetReport
43 43
      */
44 44
     static function xmlDeserialize(Reader $reader) {
45 45
 
Please login to merge, or discard this patch.
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -20,39 +20,39 @@
 block discarded – undo
20 20
  */
21 21
 class PrincipalSearchPropertySetReport implements XmlDeserializable {
22 22
 
23
-    /**
24
-     * The deserialize method is called during xml parsing.
25
-     *
26
-     * This method is called statictly, this is because in theory this method
27
-     * may be used as a type of constructor, or factory method.
28
-     *
29
-     * Often you want to return an instance of the current class, but you are
30
-     * free to return other data as well.
31
-     *
32
-     * You are responsible for advancing the reader to the next element. Not
33
-     * doing anything will result in a never-ending loop.
34
-     *
35
-     * If you just want to skip parsing for this element altogether, you can
36
-     * just call $reader->next();
37
-     *
38
-     * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
39
-     * the next element.
40
-     *
41
-     * @param Reader $reader
42
-     * @return mixed
43
-     */
44
-    static function xmlDeserialize(Reader $reader) {
45
-
46
-        if (!$reader->isEmptyElement) {
47
-            throw new BadRequest('The {DAV:}principal-search-property-set element must be empty');
48
-        }
49
-
50
-        // The element is actually empty, so there's not much to do.
51
-        $reader->next();
52
-
53
-        $self = new self();
54
-        return $self;
55
-
56
-    }
23
+	/**
24
+	 * The deserialize method is called during xml parsing.
25
+	 *
26
+	 * This method is called statictly, this is because in theory this method
27
+	 * may be used as a type of constructor, or factory method.
28
+	 *
29
+	 * Often you want to return an instance of the current class, but you are
30
+	 * free to return other data as well.
31
+	 *
32
+	 * You are responsible for advancing the reader to the next element. Not
33
+	 * doing anything will result in a never-ending loop.
34
+	 *
35
+	 * If you just want to skip parsing for this element altogether, you can
36
+	 * just call $reader->next();
37
+	 *
38
+	 * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
39
+	 * the next element.
40
+	 *
41
+	 * @param Reader $reader
42
+	 * @return mixed
43
+	 */
44
+	static function xmlDeserialize(Reader $reader) {
45
+
46
+		if (!$reader->isEmptyElement) {
47
+			throw new BadRequest('The {DAV:}principal-search-property-set element must be empty');
48
+		}
49
+
50
+		// The element is actually empty, so there's not much to do.
51
+		$reader->next();
52
+
53
+		$self = new self();
54
+		return $self;
55
+
56
+	}
57 57
 
58 58
 }
Please login to merge, or discard this patch.
Unused Use Statements   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -2,9 +2,9 @@
 block discarded – undo
2 2
 
3 3
 namespace Sabre\DAVACL\Xml\Request;
4 4
 
5
+use Sabre\DAV\Exception\BadRequest;
5 6
 use Sabre\Xml\Reader;
6 7
 use Sabre\Xml\XmlDeserializable;
7
-use Sabre\DAV\Exception\BadRequest;
8 8
 
9 9
 /**
10 10
  * PrincipalSearchPropertySetReport request parser.
Please login to merge, or discard this patch.