@@ -17,62 +17,62 @@ |
||
17 | 17 | */ |
18 | 18 | class File extends BaseFile implements IACL |
19 | 19 | { |
20 | - use ACLTrait; |
|
20 | + use ACLTrait; |
|
21 | 21 | |
22 | - /** |
|
23 | - * A list of ACL rules. |
|
24 | - * |
|
25 | - * @var array |
|
26 | - */ |
|
27 | - protected $acl; |
|
22 | + /** |
|
23 | + * A list of ACL rules. |
|
24 | + * |
|
25 | + * @var array |
|
26 | + */ |
|
27 | + protected $acl; |
|
28 | 28 | |
29 | - /** |
|
30 | - * Owner uri, or null for no owner. |
|
31 | - * |
|
32 | - * @var string|null |
|
33 | - */ |
|
34 | - protected $owner; |
|
29 | + /** |
|
30 | + * Owner uri, or null for no owner. |
|
31 | + * |
|
32 | + * @var string|null |
|
33 | + */ |
|
34 | + protected $owner; |
|
35 | 35 | |
36 | - /** |
|
37 | - * Constructor. |
|
38 | - * |
|
39 | - * @param string $path on-disk path |
|
40 | - * @param array $acl ACL rules |
|
41 | - * @param string|null $owner principal owner string |
|
42 | - */ |
|
43 | - public function __construct($path, array $acl, $owner = null) |
|
44 | - { |
|
45 | - parent::__construct($path); |
|
46 | - $this->acl = $acl; |
|
47 | - $this->owner = $owner; |
|
48 | - } |
|
36 | + /** |
|
37 | + * Constructor. |
|
38 | + * |
|
39 | + * @param string $path on-disk path |
|
40 | + * @param array $acl ACL rules |
|
41 | + * @param string|null $owner principal owner string |
|
42 | + */ |
|
43 | + public function __construct($path, array $acl, $owner = null) |
|
44 | + { |
|
45 | + parent::__construct($path); |
|
46 | + $this->acl = $acl; |
|
47 | + $this->owner = $owner; |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * Returns the owner principal. |
|
52 | - * |
|
53 | - * This must be a url to a principal, or null if there's no owner |
|
54 | - * |
|
55 | - * @return string|null |
|
56 | - */ |
|
57 | - public function getOwner() |
|
58 | - { |
|
59 | - return $this->owner; |
|
60 | - } |
|
50 | + /** |
|
51 | + * Returns the owner principal. |
|
52 | + * |
|
53 | + * This must be a url to a principal, or null if there's no owner |
|
54 | + * |
|
55 | + * @return string|null |
|
56 | + */ |
|
57 | + public function getOwner() |
|
58 | + { |
|
59 | + return $this->owner; |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Returns a list of ACE's for this node. |
|
64 | - * |
|
65 | - * Each ACE has the following properties: |
|
66 | - * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are |
|
67 | - * currently the only supported privileges |
|
68 | - * * 'principal', a url to the principal who owns the node |
|
69 | - * * 'protected' (optional), indicating that this ACE is not allowed to |
|
70 | - * be updated. |
|
71 | - * |
|
72 | - * @return array |
|
73 | - */ |
|
74 | - public function getACL() |
|
75 | - { |
|
76 | - return $this->acl; |
|
77 | - } |
|
62 | + /** |
|
63 | + * Returns a list of ACE's for this node. |
|
64 | + * |
|
65 | + * Each ACE has the following properties: |
|
66 | + * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are |
|
67 | + * currently the only supported privileges |
|
68 | + * * 'principal', a url to the principal who owns the node |
|
69 | + * * 'protected' (optional), indicating that this ACE is not allowed to |
|
70 | + * be updated. |
|
71 | + * |
|
72 | + * @return array |
|
73 | + */ |
|
74 | + public function getACL() |
|
75 | + { |
|
76 | + return $this->acl; |
|
77 | + } |
|
78 | 78 | } |
@@ -19,91 +19,91 @@ |
||
19 | 19 | */ |
20 | 20 | class Collection extends BaseCollection implements IACL |
21 | 21 | { |
22 | - use ACLTrait; |
|
22 | + use ACLTrait; |
|
23 | 23 | |
24 | - /** |
|
25 | - * A list of ACL rules. |
|
26 | - * |
|
27 | - * @var array |
|
28 | - */ |
|
29 | - protected $acl; |
|
24 | + /** |
|
25 | + * A list of ACL rules. |
|
26 | + * |
|
27 | + * @var array |
|
28 | + */ |
|
29 | + protected $acl; |
|
30 | 30 | |
31 | - /** |
|
32 | - * Owner uri, or null for no owner. |
|
33 | - * |
|
34 | - * @var string|null |
|
35 | - */ |
|
36 | - protected $owner; |
|
31 | + /** |
|
32 | + * Owner uri, or null for no owner. |
|
33 | + * |
|
34 | + * @var string|null |
|
35 | + */ |
|
36 | + protected $owner; |
|
37 | 37 | |
38 | - /** |
|
39 | - * Constructor. |
|
40 | - * |
|
41 | - * @param string $path on-disk path |
|
42 | - * @param array $acl ACL rules |
|
43 | - * @param string|null $owner principal owner string |
|
44 | - */ |
|
45 | - public function __construct($path, array $acl, $owner = null) |
|
46 | - { |
|
47 | - parent::__construct($path); |
|
48 | - $this->acl = $acl; |
|
49 | - $this->owner = $owner; |
|
50 | - } |
|
38 | + /** |
|
39 | + * Constructor. |
|
40 | + * |
|
41 | + * @param string $path on-disk path |
|
42 | + * @param array $acl ACL rules |
|
43 | + * @param string|null $owner principal owner string |
|
44 | + */ |
|
45 | + public function __construct($path, array $acl, $owner = null) |
|
46 | + { |
|
47 | + parent::__construct($path); |
|
48 | + $this->acl = $acl; |
|
49 | + $this->owner = $owner; |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Returns a specific child node, referenced by its name. |
|
54 | - * |
|
55 | - * This method must throw Sabre\DAV\Exception\NotFound if the node does not |
|
56 | - * exist. |
|
57 | - * |
|
58 | - * @param string $name |
|
59 | - * |
|
60 | - * @throws NotFound |
|
61 | - * |
|
62 | - * @return \Sabre\DAV\INode |
|
63 | - */ |
|
64 | - public function getChild($name) |
|
65 | - { |
|
66 | - $path = $this->path.'/'.$name; |
|
52 | + /** |
|
53 | + * Returns a specific child node, referenced by its name. |
|
54 | + * |
|
55 | + * This method must throw Sabre\DAV\Exception\NotFound if the node does not |
|
56 | + * exist. |
|
57 | + * |
|
58 | + * @param string $name |
|
59 | + * |
|
60 | + * @throws NotFound |
|
61 | + * |
|
62 | + * @return \Sabre\DAV\INode |
|
63 | + */ |
|
64 | + public function getChild($name) |
|
65 | + { |
|
66 | + $path = $this->path.'/'.$name; |
|
67 | 67 | |
68 | - if (!file_exists($path)) { |
|
69 | - throw new NotFound('File could not be located'); |
|
70 | - } |
|
71 | - if ('.' == $name || '..' == $name) { |
|
72 | - throw new Forbidden('Permission denied to . and ..'); |
|
73 | - } |
|
74 | - if (is_dir($path)) { |
|
75 | - return new self($path, $this->acl, $this->owner); |
|
76 | - } else { |
|
77 | - return new File($path, $this->acl, $this->owner); |
|
78 | - } |
|
79 | - } |
|
68 | + if (!file_exists($path)) { |
|
69 | + throw new NotFound('File could not be located'); |
|
70 | + } |
|
71 | + if ('.' == $name || '..' == $name) { |
|
72 | + throw new Forbidden('Permission denied to . and ..'); |
|
73 | + } |
|
74 | + if (is_dir($path)) { |
|
75 | + return new self($path, $this->acl, $this->owner); |
|
76 | + } else { |
|
77 | + return new File($path, $this->acl, $this->owner); |
|
78 | + } |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * Returns the owner principal. |
|
83 | - * |
|
84 | - * This must be a url to a principal, or null if there's no owner |
|
85 | - * |
|
86 | - * @return string|null |
|
87 | - */ |
|
88 | - public function getOwner() |
|
89 | - { |
|
90 | - return $this->owner; |
|
91 | - } |
|
81 | + /** |
|
82 | + * Returns the owner principal. |
|
83 | + * |
|
84 | + * This must be a url to a principal, or null if there's no owner |
|
85 | + * |
|
86 | + * @return string|null |
|
87 | + */ |
|
88 | + public function getOwner() |
|
89 | + { |
|
90 | + return $this->owner; |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * Returns a list of ACE's for this node. |
|
95 | - * |
|
96 | - * Each ACE has the following properties: |
|
97 | - * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are |
|
98 | - * currently the only supported privileges |
|
99 | - * * 'principal', a url to the principal who owns the node |
|
100 | - * * 'protected' (optional), indicating that this ACE is not allowed to |
|
101 | - * be updated. |
|
102 | - * |
|
103 | - * @return array |
|
104 | - */ |
|
105 | - public function getACL() |
|
106 | - { |
|
107 | - return $this->acl; |
|
108 | - } |
|
93 | + /** |
|
94 | + * Returns a list of ACE's for this node. |
|
95 | + * |
|
96 | + * Each ACE has the following properties: |
|
97 | + * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are |
|
98 | + * currently the only supported privileges |
|
99 | + * * 'principal', a url to the principal who owns the node |
|
100 | + * * 'protected' (optional), indicating that this ACE is not allowed to |
|
101 | + * be updated. |
|
102 | + * |
|
103 | + * @return array |
|
104 | + */ |
|
105 | + public function getACL() |
|
106 | + { |
|
107 | + return $this->acl; |
|
108 | + } |
|
109 | 109 | } |
@@ -23,101 +23,101 @@ |
||
23 | 23 | */ |
24 | 24 | class HomeCollection extends AbstractPrincipalCollection implements IACL |
25 | 25 | { |
26 | - use ACLTrait; |
|
26 | + use ACLTrait; |
|
27 | 27 | |
28 | - /** |
|
29 | - * Name of this collection. |
|
30 | - * |
|
31 | - * @var string |
|
32 | - */ |
|
33 | - public $collectionName = 'home'; |
|
28 | + /** |
|
29 | + * Name of this collection. |
|
30 | + * |
|
31 | + * @var string |
|
32 | + */ |
|
33 | + public $collectionName = 'home'; |
|
34 | 34 | |
35 | - /** |
|
36 | - * Path to where the users' files are actually stored. |
|
37 | - * |
|
38 | - * @var string |
|
39 | - */ |
|
40 | - protected $storagePath; |
|
35 | + /** |
|
36 | + * Path to where the users' files are actually stored. |
|
37 | + * |
|
38 | + * @var string |
|
39 | + */ |
|
40 | + protected $storagePath; |
|
41 | 41 | |
42 | - /** |
|
43 | - * Creates the home collection. |
|
44 | - * |
|
45 | - * @param string $storagePath where the actual files are stored |
|
46 | - * @param string $principalPrefix list of principals to iterate |
|
47 | - */ |
|
48 | - public function __construct(BackendInterface $principalBackend, $storagePath, $principalPrefix = 'principals') |
|
49 | - { |
|
50 | - parent::__construct($principalBackend, $principalPrefix); |
|
51 | - $this->storagePath = $storagePath; |
|
52 | - } |
|
42 | + /** |
|
43 | + * Creates the home collection. |
|
44 | + * |
|
45 | + * @param string $storagePath where the actual files are stored |
|
46 | + * @param string $principalPrefix list of principals to iterate |
|
47 | + */ |
|
48 | + public function __construct(BackendInterface $principalBackend, $storagePath, $principalPrefix = 'principals') |
|
49 | + { |
|
50 | + parent::__construct($principalBackend, $principalPrefix); |
|
51 | + $this->storagePath = $storagePath; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Returns the name of the node. |
|
56 | - * |
|
57 | - * This is used to generate the url. |
|
58 | - * |
|
59 | - * @return string |
|
60 | - */ |
|
61 | - public function getName() |
|
62 | - { |
|
63 | - return $this->collectionName; |
|
64 | - } |
|
54 | + /** |
|
55 | + * Returns the name of the node. |
|
56 | + * |
|
57 | + * This is used to generate the url. |
|
58 | + * |
|
59 | + * @return string |
|
60 | + */ |
|
61 | + public function getName() |
|
62 | + { |
|
63 | + return $this->collectionName; |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * Returns a principals' collection of files. |
|
68 | - * |
|
69 | - * The passed array contains principal information, and is guaranteed to |
|
70 | - * at least contain a uri item. Other properties may or may not be |
|
71 | - * supplied by the authentication backend. |
|
72 | - * |
|
73 | - * @return \Sabre\DAV\INode |
|
74 | - */ |
|
75 | - public function getChildForPrincipal(array $principalInfo) |
|
76 | - { |
|
77 | - $owner = $principalInfo['uri']; |
|
78 | - $acl = [ |
|
79 | - [ |
|
80 | - 'privilege' => '{DAV:}all', |
|
81 | - 'principal' => '{DAV:}owner', |
|
82 | - 'protected' => true, |
|
83 | - ], |
|
84 | - ]; |
|
66 | + /** |
|
67 | + * Returns a principals' collection of files. |
|
68 | + * |
|
69 | + * The passed array contains principal information, and is guaranteed to |
|
70 | + * at least contain a uri item. Other properties may or may not be |
|
71 | + * supplied by the authentication backend. |
|
72 | + * |
|
73 | + * @return \Sabre\DAV\INode |
|
74 | + */ |
|
75 | + public function getChildForPrincipal(array $principalInfo) |
|
76 | + { |
|
77 | + $owner = $principalInfo['uri']; |
|
78 | + $acl = [ |
|
79 | + [ |
|
80 | + 'privilege' => '{DAV:}all', |
|
81 | + 'principal' => '{DAV:}owner', |
|
82 | + 'protected' => true, |
|
83 | + ], |
|
84 | + ]; |
|
85 | 85 | |
86 | - list(, $principalBaseName) = Uri\split($owner); |
|
86 | + list(, $principalBaseName) = Uri\split($owner); |
|
87 | 87 | |
88 | - $path = $this->storagePath.'/'.$principalBaseName; |
|
88 | + $path = $this->storagePath.'/'.$principalBaseName; |
|
89 | 89 | |
90 | - if (!is_dir($path)) { |
|
91 | - mkdir($path, 0777, true); |
|
92 | - } |
|
90 | + if (!is_dir($path)) { |
|
91 | + mkdir($path, 0777, true); |
|
92 | + } |
|
93 | 93 | |
94 | - return new Collection( |
|
95 | - $path, |
|
96 | - $acl, |
|
97 | - $owner |
|
98 | - ); |
|
99 | - } |
|
94 | + return new Collection( |
|
95 | + $path, |
|
96 | + $acl, |
|
97 | + $owner |
|
98 | + ); |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Returns a list of ACE's for this node. |
|
103 | - * |
|
104 | - * Each ACE has the following properties: |
|
105 | - * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are |
|
106 | - * currently the only supported privileges |
|
107 | - * * 'principal', a url to the principal who owns the node |
|
108 | - * * 'protected' (optional), indicating that this ACE is not allowed to |
|
109 | - * be updated. |
|
110 | - * |
|
111 | - * @return array |
|
112 | - */ |
|
113 | - public function getACL() |
|
114 | - { |
|
115 | - return [ |
|
116 | - [ |
|
117 | - 'principal' => '{DAV:}authenticated', |
|
118 | - 'privilege' => '{DAV:}read', |
|
119 | - 'protected' => true, |
|
120 | - ], |
|
121 | - ]; |
|
122 | - } |
|
101 | + /** |
|
102 | + * Returns a list of ACE's for this node. |
|
103 | + * |
|
104 | + * Each ACE has the following properties: |
|
105 | + * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are |
|
106 | + * currently the only supported privileges |
|
107 | + * * 'principal', a url to the principal who owns the node |
|
108 | + * * 'protected' (optional), indicating that this ACE is not allowed to |
|
109 | + * be updated. |
|
110 | + * |
|
111 | + * @return array |
|
112 | + */ |
|
113 | + public function getACL() |
|
114 | + { |
|
115 | + return [ |
|
116 | + [ |
|
117 | + 'principal' => '{DAV:}authenticated', |
|
118 | + 'privilege' => '{DAV:}read', |
|
119 | + 'protected' => true, |
|
120 | + ], |
|
121 | + ]; |
|
122 | + } |
|
123 | 123 | } |
@@ -21,158 +21,158 @@ |
||
21 | 21 | */ |
22 | 22 | abstract class AbstractPrincipalCollection extends DAV\Collection implements IPrincipalCollection |
23 | 23 | { |
24 | - /** |
|
25 | - * Principal backend. |
|
26 | - * |
|
27 | - * @var PrincipalBackend\BackendInterface |
|
28 | - */ |
|
29 | - protected $principalBackend; |
|
30 | - |
|
31 | - /** |
|
32 | - * The path to the principals we're listing from. |
|
33 | - * |
|
34 | - * @var string |
|
35 | - */ |
|
36 | - protected $principalPrefix; |
|
37 | - |
|
38 | - /** |
|
39 | - * If this value is set to true, it effectively disables listing of users |
|
40 | - * it still allows user to find other users if they have an exact url. |
|
41 | - * |
|
42 | - * @var bool |
|
43 | - */ |
|
44 | - public $disableListing = false; |
|
45 | - |
|
46 | - /** |
|
47 | - * Creates the object. |
|
48 | - * |
|
49 | - * This object must be passed the principal backend. This object will |
|
50 | - * filter all principals from a specified prefix ($principalPrefix). The |
|
51 | - * default is 'principals', if your principals are stored in a different |
|
52 | - * collection, override $principalPrefix |
|
53 | - * |
|
54 | - * @param string $principalPrefix |
|
55 | - */ |
|
56 | - public function __construct(PrincipalBackend\BackendInterface $principalBackend, $principalPrefix = 'principals') |
|
57 | - { |
|
58 | - $this->principalPrefix = $principalPrefix; |
|
59 | - $this->principalBackend = $principalBackend; |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * This method returns a node for a principal. |
|
64 | - * |
|
65 | - * The passed array contains principal information, and is guaranteed to |
|
66 | - * at least contain a uri item. Other properties may or may not be |
|
67 | - * supplied by the authentication backend. |
|
68 | - * |
|
69 | - * @return DAV\INode |
|
70 | - */ |
|
71 | - abstract public function getChildForPrincipal(array $principalInfo); |
|
72 | - |
|
73 | - /** |
|
74 | - * Returns the name of this collection. |
|
75 | - * |
|
76 | - * @return string |
|
77 | - */ |
|
78 | - public function getName() |
|
79 | - { |
|
80 | - list(, $name) = Uri\split($this->principalPrefix); |
|
81 | - |
|
82 | - return $name; |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Return the list of users. |
|
87 | - * |
|
88 | - * @return array |
|
89 | - */ |
|
90 | - public function getChildren() |
|
91 | - { |
|
92 | - if ($this->disableListing) { |
|
93 | - throw new DAV\Exception\MethodNotAllowed('Listing members of this collection is disabled'); |
|
94 | - } |
|
95 | - $children = []; |
|
96 | - foreach ($this->principalBackend->getPrincipalsByPrefix($this->principalPrefix) as $principalInfo) { |
|
97 | - $children[] = $this->getChildForPrincipal($principalInfo); |
|
98 | - } |
|
99 | - |
|
100 | - return $children; |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Returns a child object, by its name. |
|
105 | - * |
|
106 | - * @param string $name |
|
107 | - * |
|
108 | - * @throws DAV\Exception\NotFound |
|
109 | - * |
|
110 | - * @return DAV\INode |
|
111 | - */ |
|
112 | - public function getChild($name) |
|
113 | - { |
|
114 | - $principalInfo = $this->principalBackend->getPrincipalByPath($this->principalPrefix.'/'.$name); |
|
115 | - if (!$principalInfo) { |
|
116 | - throw new DAV\Exception\NotFound('Principal with name '.$name.' not found'); |
|
117 | - } |
|
118 | - |
|
119 | - return $this->getChildForPrincipal($principalInfo); |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * This method is used to search for principals matching a set of |
|
124 | - * properties. |
|
125 | - * |
|
126 | - * This search is specifically used by RFC3744's principal-property-search |
|
127 | - * REPORT. You should at least allow searching on |
|
128 | - * http://sabredav.org/ns}email-address. |
|
129 | - * |
|
130 | - * The actual search should be a unicode-non-case-sensitive search. The |
|
131 | - * keys in searchProperties are the WebDAV property names, while the values |
|
132 | - * are the property values to search on. |
|
133 | - * |
|
134 | - * By default, if multiple properties are submitted to this method, the |
|
135 | - * various properties should be combined with 'AND'. If $test is set to |
|
136 | - * 'anyof', it should be combined using 'OR'. |
|
137 | - * |
|
138 | - * This method should simply return a list of 'child names', which may be |
|
139 | - * used to call $this->getChild in the future. |
|
140 | - * |
|
141 | - * @param string $test |
|
142 | - * |
|
143 | - * @return array |
|
144 | - */ |
|
145 | - public function searchPrincipals(array $searchProperties, $test = 'allof') |
|
146 | - { |
|
147 | - $result = $this->principalBackend->searchPrincipals($this->principalPrefix, $searchProperties, $test); |
|
148 | - $r = []; |
|
149 | - |
|
150 | - foreach ($result as $row) { |
|
151 | - list(, $r[]) = Uri\split($row); |
|
152 | - } |
|
153 | - |
|
154 | - return $r; |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * Finds a principal by its URI. |
|
159 | - * |
|
160 | - * This method may receive any type of uri, but mailto: addresses will be |
|
161 | - * the most common. |
|
162 | - * |
|
163 | - * Implementation of this API is optional. It is currently used by the |
|
164 | - * CalDAV system to find principals based on their email addresses. If this |
|
165 | - * API is not implemented, some features may not work correctly. |
|
166 | - * |
|
167 | - * This method must return a relative principal path, or null, if the |
|
168 | - * principal was not found or you refuse to find it. |
|
169 | - * |
|
170 | - * @param string $uri |
|
171 | - * |
|
172 | - * @return string |
|
173 | - */ |
|
174 | - public function findByUri($uri) |
|
175 | - { |
|
176 | - return $this->principalBackend->findByUri($uri, $this->principalPrefix); |
|
177 | - } |
|
24 | + /** |
|
25 | + * Principal backend. |
|
26 | + * |
|
27 | + * @var PrincipalBackend\BackendInterface |
|
28 | + */ |
|
29 | + protected $principalBackend; |
|
30 | + |
|
31 | + /** |
|
32 | + * The path to the principals we're listing from. |
|
33 | + * |
|
34 | + * @var string |
|
35 | + */ |
|
36 | + protected $principalPrefix; |
|
37 | + |
|
38 | + /** |
|
39 | + * If this value is set to true, it effectively disables listing of users |
|
40 | + * it still allows user to find other users if they have an exact url. |
|
41 | + * |
|
42 | + * @var bool |
|
43 | + */ |
|
44 | + public $disableListing = false; |
|
45 | + |
|
46 | + /** |
|
47 | + * Creates the object. |
|
48 | + * |
|
49 | + * This object must be passed the principal backend. This object will |
|
50 | + * filter all principals from a specified prefix ($principalPrefix). The |
|
51 | + * default is 'principals', if your principals are stored in a different |
|
52 | + * collection, override $principalPrefix |
|
53 | + * |
|
54 | + * @param string $principalPrefix |
|
55 | + */ |
|
56 | + public function __construct(PrincipalBackend\BackendInterface $principalBackend, $principalPrefix = 'principals') |
|
57 | + { |
|
58 | + $this->principalPrefix = $principalPrefix; |
|
59 | + $this->principalBackend = $principalBackend; |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * This method returns a node for a principal. |
|
64 | + * |
|
65 | + * The passed array contains principal information, and is guaranteed to |
|
66 | + * at least contain a uri item. Other properties may or may not be |
|
67 | + * supplied by the authentication backend. |
|
68 | + * |
|
69 | + * @return DAV\INode |
|
70 | + */ |
|
71 | + abstract public function getChildForPrincipal(array $principalInfo); |
|
72 | + |
|
73 | + /** |
|
74 | + * Returns the name of this collection. |
|
75 | + * |
|
76 | + * @return string |
|
77 | + */ |
|
78 | + public function getName() |
|
79 | + { |
|
80 | + list(, $name) = Uri\split($this->principalPrefix); |
|
81 | + |
|
82 | + return $name; |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Return the list of users. |
|
87 | + * |
|
88 | + * @return array |
|
89 | + */ |
|
90 | + public function getChildren() |
|
91 | + { |
|
92 | + if ($this->disableListing) { |
|
93 | + throw new DAV\Exception\MethodNotAllowed('Listing members of this collection is disabled'); |
|
94 | + } |
|
95 | + $children = []; |
|
96 | + foreach ($this->principalBackend->getPrincipalsByPrefix($this->principalPrefix) as $principalInfo) { |
|
97 | + $children[] = $this->getChildForPrincipal($principalInfo); |
|
98 | + } |
|
99 | + |
|
100 | + return $children; |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Returns a child object, by its name. |
|
105 | + * |
|
106 | + * @param string $name |
|
107 | + * |
|
108 | + * @throws DAV\Exception\NotFound |
|
109 | + * |
|
110 | + * @return DAV\INode |
|
111 | + */ |
|
112 | + public function getChild($name) |
|
113 | + { |
|
114 | + $principalInfo = $this->principalBackend->getPrincipalByPath($this->principalPrefix.'/'.$name); |
|
115 | + if (!$principalInfo) { |
|
116 | + throw new DAV\Exception\NotFound('Principal with name '.$name.' not found'); |
|
117 | + } |
|
118 | + |
|
119 | + return $this->getChildForPrincipal($principalInfo); |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * This method is used to search for principals matching a set of |
|
124 | + * properties. |
|
125 | + * |
|
126 | + * This search is specifically used by RFC3744's principal-property-search |
|
127 | + * REPORT. You should at least allow searching on |
|
128 | + * http://sabredav.org/ns}email-address. |
|
129 | + * |
|
130 | + * The actual search should be a unicode-non-case-sensitive search. The |
|
131 | + * keys in searchProperties are the WebDAV property names, while the values |
|
132 | + * are the property values to search on. |
|
133 | + * |
|
134 | + * By default, if multiple properties are submitted to this method, the |
|
135 | + * various properties should be combined with 'AND'. If $test is set to |
|
136 | + * 'anyof', it should be combined using 'OR'. |
|
137 | + * |
|
138 | + * This method should simply return a list of 'child names', which may be |
|
139 | + * used to call $this->getChild in the future. |
|
140 | + * |
|
141 | + * @param string $test |
|
142 | + * |
|
143 | + * @return array |
|
144 | + */ |
|
145 | + public function searchPrincipals(array $searchProperties, $test = 'allof') |
|
146 | + { |
|
147 | + $result = $this->principalBackend->searchPrincipals($this->principalPrefix, $searchProperties, $test); |
|
148 | + $r = []; |
|
149 | + |
|
150 | + foreach ($result as $row) { |
|
151 | + list(, $r[]) = Uri\split($row); |
|
152 | + } |
|
153 | + |
|
154 | + return $r; |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * Finds a principal by its URI. |
|
159 | + * |
|
160 | + * This method may receive any type of uri, but mailto: addresses will be |
|
161 | + * the most common. |
|
162 | + * |
|
163 | + * Implementation of this API is optional. It is currently used by the |
|
164 | + * CalDAV system to find principals based on their email addresses. If this |
|
165 | + * API is not implemented, some features may not work correctly. |
|
166 | + * |
|
167 | + * This method must return a relative principal path, or null, if the |
|
168 | + * principal was not found or you refuse to find it. |
|
169 | + * |
|
170 | + * @param string $uri |
|
171 | + * |
|
172 | + * @return string |
|
173 | + */ |
|
174 | + public function findByUri($uri) |
|
175 | + { |
|
176 | + return $this->principalBackend->findByUri($uri, $this->principalPrefix); |
|
177 | + } |
|
178 | 178 | } |
@@ -21,46 +21,46 @@ |
||
21 | 21 | */ |
22 | 22 | class AclPrincipalPropSetReport implements XmlDeserializable |
23 | 23 | { |
24 | - public $properties = []; |
|
24 | + public $properties = []; |
|
25 | 25 | |
26 | - /** |
|
27 | - * The deserialize method is called during xml parsing. |
|
28 | - * |
|
29 | - * This method is called statically, this is because in theory this method |
|
30 | - * may be used as a type of constructor, or factory method. |
|
31 | - * |
|
32 | - * Often you want to return an instance of the current class, but you are |
|
33 | - * free to return other data as well. |
|
34 | - * |
|
35 | - * You are responsible for advancing the reader to the next element. Not |
|
36 | - * doing anything will result in a never-ending loop. |
|
37 | - * |
|
38 | - * If you just want to skip parsing for this element altogether, you can |
|
39 | - * just call $reader->next(); |
|
40 | - * |
|
41 | - * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
42 | - * the next element. |
|
43 | - * |
|
44 | - * @return mixed |
|
45 | - */ |
|
46 | - public static function xmlDeserialize(Reader $reader) |
|
47 | - { |
|
48 | - $reader->pushContext(); |
|
49 | - $reader->elementMap['{DAV:}prop'] = 'Sabre\Xml\Deserializer\enum'; |
|
26 | + /** |
|
27 | + * The deserialize method is called during xml parsing. |
|
28 | + * |
|
29 | + * This method is called statically, this is because in theory this method |
|
30 | + * may be used as a type of constructor, or factory method. |
|
31 | + * |
|
32 | + * Often you want to return an instance of the current class, but you are |
|
33 | + * free to return other data as well. |
|
34 | + * |
|
35 | + * You are responsible for advancing the reader to the next element. Not |
|
36 | + * doing anything will result in a never-ending loop. |
|
37 | + * |
|
38 | + * If you just want to skip parsing for this element altogether, you can |
|
39 | + * just call $reader->next(); |
|
40 | + * |
|
41 | + * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
42 | + * the next element. |
|
43 | + * |
|
44 | + * @return mixed |
|
45 | + */ |
|
46 | + public static function xmlDeserialize(Reader $reader) |
|
47 | + { |
|
48 | + $reader->pushContext(); |
|
49 | + $reader->elementMap['{DAV:}prop'] = 'Sabre\Xml\Deserializer\enum'; |
|
50 | 50 | |
51 | - $elems = Deserializer\keyValue( |
|
52 | - $reader, |
|
53 | - 'DAV:' |
|
54 | - ); |
|
51 | + $elems = Deserializer\keyValue( |
|
52 | + $reader, |
|
53 | + 'DAV:' |
|
54 | + ); |
|
55 | 55 | |
56 | - $reader->popContext(); |
|
56 | + $reader->popContext(); |
|
57 | 57 | |
58 | - $report = new self(); |
|
58 | + $report = new self(); |
|
59 | 59 | |
60 | - if (!empty($elems['prop'])) { |
|
61 | - $report->properties = $elems['prop']; |
|
62 | - } |
|
60 | + if (!empty($elems['prop'])) { |
|
61 | + $report->properties = $elems['prop']; |
|
62 | + } |
|
63 | 63 | |
64 | - return $report; |
|
65 | - } |
|
64 | + return $report; |
|
65 | + } |
|
66 | 66 | } |
@@ -22,85 +22,85 @@ |
||
22 | 22 | */ |
23 | 23 | class PrincipalMatchReport implements XmlDeserializable |
24 | 24 | { |
25 | - /** |
|
26 | - * Report on a list of principals that match the current principal. |
|
27 | - */ |
|
28 | - const SELF = 1; |
|
29 | - |
|
30 | - /** |
|
31 | - * Report on a property on resources, such as {DAV:}owner, that match the current principal. |
|
32 | - */ |
|
33 | - const PRINCIPAL_PROPERTY = 2; |
|
34 | - |
|
35 | - /** |
|
36 | - * Must be SELF or PRINCIPAL_PROPERTY. |
|
37 | - * |
|
38 | - * @var int |
|
39 | - */ |
|
40 | - public $type; |
|
41 | - |
|
42 | - /** |
|
43 | - * List of properties that are being requested for matching resources. |
|
44 | - * |
|
45 | - * @var string[] |
|
46 | - */ |
|
47 | - public $properties = []; |
|
48 | - |
|
49 | - /** |
|
50 | - * If $type = PRINCIPAL_PROPERTY, which WebDAV property we should compare |
|
51 | - * to the current principal. |
|
52 | - * |
|
53 | - * @var string |
|
54 | - */ |
|
55 | - public $principalProperty; |
|
56 | - |
|
57 | - /** |
|
58 | - * The deserialize method is called during xml parsing. |
|
59 | - * |
|
60 | - * This method is called statically, this is because in theory this method |
|
61 | - * may be used as a type of constructor, or factory method. |
|
62 | - * |
|
63 | - * Often you want to return an instance of the current class, but you are |
|
64 | - * free to return other data as well. |
|
65 | - * |
|
66 | - * You are responsible for advancing the reader to the next element. Not |
|
67 | - * doing anything will result in a never-ending loop. |
|
68 | - * |
|
69 | - * If you just want to skip parsing for this element altogether, you can |
|
70 | - * just call $reader->next(); |
|
71 | - * |
|
72 | - * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
73 | - * the next element. |
|
74 | - * |
|
75 | - * @return mixed |
|
76 | - */ |
|
77 | - public static function xmlDeserialize(Reader $reader) |
|
78 | - { |
|
79 | - $reader->pushContext(); |
|
80 | - $reader->elementMap['{DAV:}prop'] = 'Sabre\Xml\Deserializer\enum'; |
|
81 | - |
|
82 | - $elems = Deserializer\keyValue( |
|
83 | - $reader, |
|
84 | - 'DAV:' |
|
85 | - ); |
|
86 | - |
|
87 | - $reader->popContext(); |
|
88 | - |
|
89 | - $principalMatch = new self(); |
|
90 | - |
|
91 | - if (array_key_exists('self', $elems)) { |
|
92 | - $principalMatch->type = self::SELF; |
|
93 | - } |
|
94 | - |
|
95 | - if (array_key_exists('principal-property', $elems)) { |
|
96 | - $principalMatch->type = self::PRINCIPAL_PROPERTY; |
|
97 | - $principalMatch->principalProperty = $elems['principal-property'][0]['name']; |
|
98 | - } |
|
99 | - |
|
100 | - if (!empty($elems['prop'])) { |
|
101 | - $principalMatch->properties = $elems['prop']; |
|
102 | - } |
|
103 | - |
|
104 | - return $principalMatch; |
|
105 | - } |
|
25 | + /** |
|
26 | + * Report on a list of principals that match the current principal. |
|
27 | + */ |
|
28 | + const SELF = 1; |
|
29 | + |
|
30 | + /** |
|
31 | + * Report on a property on resources, such as {DAV:}owner, that match the current principal. |
|
32 | + */ |
|
33 | + const PRINCIPAL_PROPERTY = 2; |
|
34 | + |
|
35 | + /** |
|
36 | + * Must be SELF or PRINCIPAL_PROPERTY. |
|
37 | + * |
|
38 | + * @var int |
|
39 | + */ |
|
40 | + public $type; |
|
41 | + |
|
42 | + /** |
|
43 | + * List of properties that are being requested for matching resources. |
|
44 | + * |
|
45 | + * @var string[] |
|
46 | + */ |
|
47 | + public $properties = []; |
|
48 | + |
|
49 | + /** |
|
50 | + * If $type = PRINCIPAL_PROPERTY, which WebDAV property we should compare |
|
51 | + * to the current principal. |
|
52 | + * |
|
53 | + * @var string |
|
54 | + */ |
|
55 | + public $principalProperty; |
|
56 | + |
|
57 | + /** |
|
58 | + * The deserialize method is called during xml parsing. |
|
59 | + * |
|
60 | + * This method is called statically, this is because in theory this method |
|
61 | + * may be used as a type of constructor, or factory method. |
|
62 | + * |
|
63 | + * Often you want to return an instance of the current class, but you are |
|
64 | + * free to return other data as well. |
|
65 | + * |
|
66 | + * You are responsible for advancing the reader to the next element. Not |
|
67 | + * doing anything will result in a never-ending loop. |
|
68 | + * |
|
69 | + * If you just want to skip parsing for this element altogether, you can |
|
70 | + * just call $reader->next(); |
|
71 | + * |
|
72 | + * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
73 | + * the next element. |
|
74 | + * |
|
75 | + * @return mixed |
|
76 | + */ |
|
77 | + public static function xmlDeserialize(Reader $reader) |
|
78 | + { |
|
79 | + $reader->pushContext(); |
|
80 | + $reader->elementMap['{DAV:}prop'] = 'Sabre\Xml\Deserializer\enum'; |
|
81 | + |
|
82 | + $elems = Deserializer\keyValue( |
|
83 | + $reader, |
|
84 | + 'DAV:' |
|
85 | + ); |
|
86 | + |
|
87 | + $reader->popContext(); |
|
88 | + |
|
89 | + $principalMatch = new self(); |
|
90 | + |
|
91 | + if (array_key_exists('self', $elems)) { |
|
92 | + $principalMatch->type = self::SELF; |
|
93 | + } |
|
94 | + |
|
95 | + if (array_key_exists('principal-property', $elems)) { |
|
96 | + $principalMatch->type = self::PRINCIPAL_PROPERTY; |
|
97 | + $principalMatch->principalProperty = $elems['principal-property'][0]['name']; |
|
98 | + } |
|
99 | + |
|
100 | + if (!empty($elems['prop'])) { |
|
101 | + $principalMatch->properties = $elems['prop']; |
|
102 | + } |
|
103 | + |
|
104 | + return $principalMatch; |
|
105 | + } |
|
106 | 106 | } |
@@ -22,37 +22,37 @@ |
||
22 | 22 | */ |
23 | 23 | class PrincipalSearchPropertySetReport implements XmlDeserializable |
24 | 24 | { |
25 | - /** |
|
26 | - * The deserialize method is called during xml parsing. |
|
27 | - * |
|
28 | - * This method is called statically, this is because in theory this method |
|
29 | - * may be used as a type of constructor, or factory method. |
|
30 | - * |
|
31 | - * Often you want to return an instance of the current class, but you are |
|
32 | - * free to return other data as well. |
|
33 | - * |
|
34 | - * You are responsible for advancing the reader to the next element. Not |
|
35 | - * doing anything will result in a never-ending loop. |
|
36 | - * |
|
37 | - * If you just want to skip parsing for this element altogether, you can |
|
38 | - * just call $reader->next(); |
|
39 | - * |
|
40 | - * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
41 | - * the next element. |
|
42 | - * |
|
43 | - * @return mixed |
|
44 | - */ |
|
45 | - public static function xmlDeserialize(Reader $reader) |
|
46 | - { |
|
47 | - if (!$reader->isEmptyElement) { |
|
48 | - throw new BadRequest('The {DAV:}principal-search-property-set element must be empty'); |
|
49 | - } |
|
25 | + /** |
|
26 | + * The deserialize method is called during xml parsing. |
|
27 | + * |
|
28 | + * This method is called statically, this is because in theory this method |
|
29 | + * may be used as a type of constructor, or factory method. |
|
30 | + * |
|
31 | + * Often you want to return an instance of the current class, but you are |
|
32 | + * free to return other data as well. |
|
33 | + * |
|
34 | + * You are responsible for advancing the reader to the next element. Not |
|
35 | + * doing anything will result in a never-ending loop. |
|
36 | + * |
|
37 | + * If you just want to skip parsing for this element altogether, you can |
|
38 | + * just call $reader->next(); |
|
39 | + * |
|
40 | + * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
41 | + * the next element. |
|
42 | + * |
|
43 | + * @return mixed |
|
44 | + */ |
|
45 | + public static function xmlDeserialize(Reader $reader) |
|
46 | + { |
|
47 | + if (!$reader->isEmptyElement) { |
|
48 | + throw new BadRequest('The {DAV:}principal-search-property-set element must be empty'); |
|
49 | + } |
|
50 | 50 | |
51 | - // The element is actually empty, so there's not much to do. |
|
52 | - $reader->next(); |
|
51 | + // The element is actually empty, so there's not much to do. |
|
52 | + $reader->next(); |
|
53 | 53 | |
54 | - $self = new self(); |
|
54 | + $self = new self(); |
|
55 | 55 | |
56 | - return $self; |
|
57 | - } |
|
56 | + return $self; |
|
57 | + } |
|
58 | 58 | } |
@@ -20,81 +20,81 @@ |
||
20 | 20 | */ |
21 | 21 | class ExpandPropertyReport implements XmlDeserializable |
22 | 22 | { |
23 | - /** |
|
24 | - * An array with requested properties. |
|
25 | - * |
|
26 | - * The requested properties will be used as keys in this array. The value |
|
27 | - * is normally null. |
|
28 | - * |
|
29 | - * If the value is an array though, it means the property must be expanded. |
|
30 | - * Within the array, the sub-properties, which themselves may be null or |
|
31 | - * arrays. |
|
32 | - * |
|
33 | - * @var array |
|
34 | - */ |
|
35 | - public $properties; |
|
23 | + /** |
|
24 | + * An array with requested properties. |
|
25 | + * |
|
26 | + * The requested properties will be used as keys in this array. The value |
|
27 | + * is normally null. |
|
28 | + * |
|
29 | + * If the value is an array though, it means the property must be expanded. |
|
30 | + * Within the array, the sub-properties, which themselves may be null or |
|
31 | + * arrays. |
|
32 | + * |
|
33 | + * @var array |
|
34 | + */ |
|
35 | + public $properties; |
|
36 | 36 | |
37 | - /** |
|
38 | - * The deserialize method is called during xml parsing. |
|
39 | - * |
|
40 | - * This method is called statically, this is because in theory this method |
|
41 | - * may be used as a type of constructor, or factory method. |
|
42 | - * |
|
43 | - * Often you want to return an instance of the current class, but you are |
|
44 | - * free to return other data as well. |
|
45 | - * |
|
46 | - * You are responsible for advancing the reader to the next element. Not |
|
47 | - * doing anything will result in a never-ending loop. |
|
48 | - * |
|
49 | - * If you just want to skip parsing for this element altogether, you can |
|
50 | - * just call $reader->next(); |
|
51 | - * |
|
52 | - * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
53 | - * the next element. |
|
54 | - * |
|
55 | - * @return mixed |
|
56 | - */ |
|
57 | - public static function xmlDeserialize(Reader $reader) |
|
58 | - { |
|
59 | - $elems = $reader->parseInnerTree(); |
|
37 | + /** |
|
38 | + * The deserialize method is called during xml parsing. |
|
39 | + * |
|
40 | + * This method is called statically, this is because in theory this method |
|
41 | + * may be used as a type of constructor, or factory method. |
|
42 | + * |
|
43 | + * Often you want to return an instance of the current class, but you are |
|
44 | + * free to return other data as well. |
|
45 | + * |
|
46 | + * You are responsible for advancing the reader to the next element. Not |
|
47 | + * doing anything will result in a never-ending loop. |
|
48 | + * |
|
49 | + * If you just want to skip parsing for this element altogether, you can |
|
50 | + * just call $reader->next(); |
|
51 | + * |
|
52 | + * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
53 | + * the next element. |
|
54 | + * |
|
55 | + * @return mixed |
|
56 | + */ |
|
57 | + public static function xmlDeserialize(Reader $reader) |
|
58 | + { |
|
59 | + $elems = $reader->parseInnerTree(); |
|
60 | 60 | |
61 | - $obj = new self(); |
|
62 | - $obj->properties = self::traverse($elems); |
|
61 | + $obj = new self(); |
|
62 | + $obj->properties = self::traverse($elems); |
|
63 | 63 | |
64 | - return $obj; |
|
65 | - } |
|
64 | + return $obj; |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * This method is used by deserializeXml, to recursively parse the |
|
69 | - * {DAV:}property elements. |
|
70 | - * |
|
71 | - * @param array $elems |
|
72 | - * |
|
73 | - * @return array |
|
74 | - */ |
|
75 | - private static function traverse($elems) |
|
76 | - { |
|
77 | - $result = []; |
|
67 | + /** |
|
68 | + * This method is used by deserializeXml, to recursively parse the |
|
69 | + * {DAV:}property elements. |
|
70 | + * |
|
71 | + * @param array $elems |
|
72 | + * |
|
73 | + * @return array |
|
74 | + */ |
|
75 | + private static function traverse($elems) |
|
76 | + { |
|
77 | + $result = []; |
|
78 | 78 | |
79 | - foreach ($elems as $elem) { |
|
80 | - if ('{DAV:}property' !== $elem['name']) { |
|
81 | - continue; |
|
82 | - } |
|
79 | + foreach ($elems as $elem) { |
|
80 | + if ('{DAV:}property' !== $elem['name']) { |
|
81 | + continue; |
|
82 | + } |
|
83 | 83 | |
84 | - $namespace = isset($elem['attributes']['namespace']) ? |
|
85 | - $elem['attributes']['namespace'] : |
|
86 | - 'DAV:'; |
|
84 | + $namespace = isset($elem['attributes']['namespace']) ? |
|
85 | + $elem['attributes']['namespace'] : |
|
86 | + 'DAV:'; |
|
87 | 87 | |
88 | - $propName = '{'.$namespace.'}'.$elem['attributes']['name']; |
|
88 | + $propName = '{'.$namespace.'}'.$elem['attributes']['name']; |
|
89 | 89 | |
90 | - $value = null; |
|
91 | - if (is_array($elem['value'])) { |
|
92 | - $value = self::traverse($elem['value']); |
|
93 | - } |
|
90 | + $value = null; |
|
91 | + if (is_array($elem['value'])) { |
|
92 | + $value = self::traverse($elem['value']); |
|
93 | + } |
|
94 | 94 | |
95 | - $result[$propName] = $value; |
|
96 | - } |
|
95 | + $result[$propName] = $value; |
|
96 | + } |
|
97 | 97 | |
98 | - return $result; |
|
99 | - } |
|
98 | + return $result; |
|
99 | + } |
|
100 | 100 | } |
@@ -82,8 +82,7 @@ |
||
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 |
@@ -22,101 +22,101 @@ |
||
22 | 22 | */ |
23 | 23 | class PrincipalPropertySearchReport implements XmlDeserializable |
24 | 24 | { |
25 | - /** |
|
26 | - * The requested properties. |
|
27 | - * |
|
28 | - * @var array|null |
|
29 | - */ |
|
30 | - public $properties; |
|
25 | + /** |
|
26 | + * The requested properties. |
|
27 | + * |
|
28 | + * @var array|null |
|
29 | + */ |
|
30 | + public $properties; |
|
31 | 31 | |
32 | - /** |
|
33 | - * searchProperties. |
|
34 | - * |
|
35 | - * @var array |
|
36 | - */ |
|
37 | - public $searchProperties = []; |
|
32 | + /** |
|
33 | + * searchProperties. |
|
34 | + * |
|
35 | + * @var array |
|
36 | + */ |
|
37 | + public $searchProperties = []; |
|
38 | 38 | |
39 | - /** |
|
40 | - * By default the property search will be conducted on the url of the http |
|
41 | - * request. If this is set to true, it will be applied to the principal |
|
42 | - * collection set instead. |
|
43 | - * |
|
44 | - * @var bool |
|
45 | - */ |
|
46 | - public $applyToPrincipalCollectionSet = false; |
|
39 | + /** |
|
40 | + * By default the property search will be conducted on the url of the http |
|
41 | + * request. If this is set to true, it will be applied to the principal |
|
42 | + * collection set instead. |
|
43 | + * |
|
44 | + * @var bool |
|
45 | + */ |
|
46 | + public $applyToPrincipalCollectionSet = false; |
|
47 | 47 | |
48 | - /** |
|
49 | - * Search for principals matching ANY of the properties (OR) or a ALL of |
|
50 | - * the properties (AND). |
|
51 | - * |
|
52 | - * This property is either "anyof" or "allof". |
|
53 | - * |
|
54 | - * @var string |
|
55 | - */ |
|
56 | - public $test; |
|
48 | + /** |
|
49 | + * Search for principals matching ANY of the properties (OR) or a ALL of |
|
50 | + * the properties (AND). |
|
51 | + * |
|
52 | + * This property is either "anyof" or "allof". |
|
53 | + * |
|
54 | + * @var string |
|
55 | + */ |
|
56 | + public $test; |
|
57 | 57 | |
58 | - /** |
|
59 | - * The deserialize method is called during xml parsing. |
|
60 | - * |
|
61 | - * This method is called statically, this is because in theory this method |
|
62 | - * may be used as a type of constructor, or factory method. |
|
63 | - * |
|
64 | - * Often you want to return an instance of the current class, but you are |
|
65 | - * free to return other data as well. |
|
66 | - * |
|
67 | - * You are responsible for advancing the reader to the next element. Not |
|
68 | - * doing anything will result in a never-ending loop. |
|
69 | - * |
|
70 | - * If you just want to skip parsing for this element altogether, you can |
|
71 | - * just call $reader->next(); |
|
72 | - * |
|
73 | - * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
74 | - * the next element. |
|
75 | - * |
|
76 | - * @return mixed |
|
77 | - */ |
|
78 | - public static function xmlDeserialize(Reader $reader) |
|
79 | - { |
|
80 | - $self = new self(); |
|
58 | + /** |
|
59 | + * The deserialize method is called during xml parsing. |
|
60 | + * |
|
61 | + * This method is called statically, this is because in theory this method |
|
62 | + * may be used as a type of constructor, or factory method. |
|
63 | + * |
|
64 | + * Often you want to return an instance of the current class, but you are |
|
65 | + * free to return other data as well. |
|
66 | + * |
|
67 | + * You are responsible for advancing the reader to the next element. Not |
|
68 | + * doing anything will result in a never-ending loop. |
|
69 | + * |
|
70 | + * If you just want to skip parsing for this element altogether, you can |
|
71 | + * just call $reader->next(); |
|
72 | + * |
|
73 | + * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
74 | + * the next element. |
|
75 | + * |
|
76 | + * @return mixed |
|
77 | + */ |
|
78 | + public static function xmlDeserialize(Reader $reader) |
|
79 | + { |
|
80 | + $self = new self(); |
|
81 | 81 | |
82 | - $foundSearchProp = false; |
|
83 | - $self->test = 'allof'; |
|
84 | - if ('anyof' === $reader->getAttribute('test')) { |
|
85 | - $self->test = 'anyof'; |
|
86 | - } |
|
82 | + $foundSearchProp = false; |
|
83 | + $self->test = 'allof'; |
|
84 | + if ('anyof' === $reader->getAttribute('test')) { |
|
85 | + $self->test = 'anyof'; |
|
86 | + } |
|
87 | 87 | |
88 | - $elemMap = [ |
|
89 | - '{DAV:}property-search' => 'Sabre\\Xml\\Element\\KeyValue', |
|
90 | - '{DAV:}prop' => 'Sabre\\Xml\\Element\\KeyValue', |
|
91 | - ]; |
|
88 | + $elemMap = [ |
|
89 | + '{DAV:}property-search' => 'Sabre\\Xml\\Element\\KeyValue', |
|
90 | + '{DAV:}prop' => 'Sabre\\Xml\\Element\\KeyValue', |
|
91 | + ]; |
|
92 | 92 | |
93 | - foreach ($reader->parseInnerTree($elemMap) as $elem) { |
|
94 | - switch ($elem['name']) { |
|
95 | - case '{DAV:}prop': |
|
96 | - $self->properties = array_keys($elem['value']); |
|
97 | - break; |
|
98 | - case '{DAV:}property-search': |
|
99 | - $foundSearchProp = true; |
|
100 | - // This property has two sub-elements: |
|
101 | - // {DAV:}prop - The property to be searched on. This may |
|
102 | - // also be more than one |
|
103 | - // {DAV:}match - The value to match with |
|
104 | - if (!isset($elem['value']['{DAV:}prop']) || !isset($elem['value']['{DAV:}match'])) { |
|
105 | - throw new BadRequest('The {DAV:}property-search element must contain one {DAV:}match and one {DAV:}prop element'); |
|
106 | - } |
|
107 | - foreach ($elem['value']['{DAV:}prop'] as $propName => $discard) { |
|
108 | - $self->searchProperties[$propName] = $elem['value']['{DAV:}match']; |
|
109 | - } |
|
110 | - break; |
|
111 | - case '{DAV:}apply-to-principal-collection-set': |
|
112 | - $self->applyToPrincipalCollectionSet = true; |
|
113 | - break; |
|
114 | - } |
|
115 | - } |
|
116 | - if (!$foundSearchProp) { |
|
117 | - throw new BadRequest('The {DAV:}principal-property-search report must contain at least 1 {DAV:}property-search element'); |
|
118 | - } |
|
93 | + foreach ($reader->parseInnerTree($elemMap) as $elem) { |
|
94 | + switch ($elem['name']) { |
|
95 | + case '{DAV:}prop': |
|
96 | + $self->properties = array_keys($elem['value']); |
|
97 | + break; |
|
98 | + case '{DAV:}property-search': |
|
99 | + $foundSearchProp = true; |
|
100 | + // This property has two sub-elements: |
|
101 | + // {DAV:}prop - The property to be searched on. This may |
|
102 | + // also be more than one |
|
103 | + // {DAV:}match - The value to match with |
|
104 | + if (!isset($elem['value']['{DAV:}prop']) || !isset($elem['value']['{DAV:}match'])) { |
|
105 | + throw new BadRequest('The {DAV:}property-search element must contain one {DAV:}match and one {DAV:}prop element'); |
|
106 | + } |
|
107 | + foreach ($elem['value']['{DAV:}prop'] as $propName => $discard) { |
|
108 | + $self->searchProperties[$propName] = $elem['value']['{DAV:}match']; |
|
109 | + } |
|
110 | + break; |
|
111 | + case '{DAV:}apply-to-principal-collection-set': |
|
112 | + $self->applyToPrincipalCollectionSet = true; |
|
113 | + break; |
|
114 | + } |
|
115 | + } |
|
116 | + if (!$foundSearchProp) { |
|
117 | + throw new BadRequest('The {DAV:}principal-property-search report must contain at least 1 {DAV:}property-search element'); |
|
118 | + } |
|
119 | 119 | |
120 | - return $self; |
|
121 | - } |
|
120 | + return $self; |
|
121 | + } |
|
122 | 122 | } |