@@ -23,171 +23,171 @@ |
||
23 | 23 | */ |
24 | 24 | class AddressBookQueryReport implements XmlDeserializable |
25 | 25 | { |
26 | - /** |
|
27 | - * An array with requested properties. |
|
28 | - * |
|
29 | - * @var array |
|
30 | - */ |
|
31 | - public $properties; |
|
32 | - |
|
33 | - /** |
|
34 | - * An array with requested vcard properties. |
|
35 | - * |
|
36 | - * @var array |
|
37 | - */ |
|
38 | - public $addressDataProperties = []; |
|
39 | - |
|
40 | - /** |
|
41 | - * List of property/component filters. |
|
42 | - * |
|
43 | - * This is an array with filters. Every item is a property filter. Every |
|
44 | - * property filter has the following keys: |
|
45 | - * * name - name of the component to filter on |
|
46 | - * * test - anyof or allof |
|
47 | - * * is-not-defined - Test for non-existence |
|
48 | - * * param-filters - A list of parameter filters on the property |
|
49 | - * * text-matches - A list of text values the filter needs to match |
|
50 | - * |
|
51 | - * Each param-filter has the following keys: |
|
52 | - * * name - name of the parameter |
|
53 | - * * is-not-defined - Test for non-existence |
|
54 | - * * text-match - Match the parameter value |
|
55 | - * |
|
56 | - * Each text-match in property filters, and the single text-match in |
|
57 | - * param-filters have the following keys: |
|
58 | - * |
|
59 | - * * value - value to match |
|
60 | - * * match-type - contains, starts-with, ends-with, equals |
|
61 | - * * negate-condition - Do the opposite match |
|
62 | - * * collation - Usually i;unicode-casemap |
|
63 | - * |
|
64 | - * @var array |
|
65 | - */ |
|
66 | - public $filters; |
|
67 | - |
|
68 | - /** |
|
69 | - * The number of results the client wants. |
|
70 | - * |
|
71 | - * null means it wasn't specified, which in most cases means 'all results'. |
|
72 | - * |
|
73 | - * @var int|null |
|
74 | - */ |
|
75 | - public $limit; |
|
76 | - |
|
77 | - /** |
|
78 | - * Either 'anyof' or 'allof'. |
|
79 | - * |
|
80 | - * @var string |
|
81 | - */ |
|
82 | - public $test; |
|
83 | - |
|
84 | - /** |
|
85 | - * The mimetype of the content that should be returend. Usually |
|
86 | - * text/vcard. |
|
87 | - * |
|
88 | - * @var string |
|
89 | - */ |
|
90 | - public $contentType = null; |
|
91 | - |
|
92 | - /** |
|
93 | - * The version of vcard data that should be returned. Usually 3.0, |
|
94 | - * referring to vCard 3.0. |
|
95 | - * |
|
96 | - * @var string |
|
97 | - */ |
|
98 | - public $version = null; |
|
99 | - |
|
100 | - /** |
|
101 | - * The deserialize method is called during xml parsing. |
|
102 | - * |
|
103 | - * This method is called statically, this is because in theory this method |
|
104 | - * may be used as a type of constructor, or factory method. |
|
105 | - * |
|
106 | - * Often you want to return an instance of the current class, but you are |
|
107 | - * free to return other data as well. |
|
108 | - * |
|
109 | - * You are responsible for advancing the reader to the next element. Not |
|
110 | - * doing anything will result in a never-ending loop. |
|
111 | - * |
|
112 | - * If you just want to skip parsing for this element altogether, you can |
|
113 | - * just call $reader->next(); |
|
114 | - * |
|
115 | - * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
116 | - * the next element. |
|
117 | - * |
|
118 | - * @return mixed |
|
119 | - */ |
|
120 | - public static function xmlDeserialize(Reader $reader) |
|
121 | - { |
|
122 | - $elems = (array) $reader->parseInnerTree([ |
|
123 | - '{urn:ietf:params:xml:ns:carddav}prop-filter' => 'Sabre\\CardDAV\\Xml\\Filter\\PropFilter', |
|
124 | - '{urn:ietf:params:xml:ns:carddav}param-filter' => 'Sabre\\CardDAV\\Xml\\Filter\\ParamFilter', |
|
125 | - '{urn:ietf:params:xml:ns:carddav}address-data' => 'Sabre\\CardDAV\\Xml\\Filter\\AddressData', |
|
126 | - '{DAV:}prop' => 'Sabre\\Xml\\Element\\KeyValue', |
|
127 | - ]); |
|
128 | - |
|
129 | - $newProps = [ |
|
130 | - 'filters' => null, |
|
131 | - 'properties' => [], |
|
132 | - 'test' => 'anyof', |
|
133 | - 'limit' => null, |
|
134 | - ]; |
|
135 | - |
|
136 | - if (!is_array($elems)) { |
|
137 | - $elems = []; |
|
138 | - } |
|
139 | - |
|
140 | - foreach ($elems as $elem) { |
|
141 | - switch ($elem['name']) { |
|
142 | - case '{DAV:}prop': |
|
143 | - $newProps['properties'] = array_keys($elem['value']); |
|
144 | - if (isset($elem['value']['{'.Plugin::NS_CARDDAV.'}address-data'])) { |
|
145 | - $newProps += $elem['value']['{'.Plugin::NS_CARDDAV.'}address-data']; |
|
146 | - } |
|
147 | - break; |
|
148 | - case '{'.Plugin::NS_CARDDAV.'}filter': |
|
149 | - if (!is_null($newProps['filters'])) { |
|
150 | - throw new BadRequest('You can only include 1 {'.Plugin::NS_CARDDAV.'}filter element'); |
|
151 | - } |
|
152 | - if (isset($elem['attributes']['test'])) { |
|
153 | - $newProps['test'] = $elem['attributes']['test']; |
|
154 | - if ('allof' !== $newProps['test'] && 'anyof' !== $newProps['test']) { |
|
155 | - throw new BadRequest('The "test" attribute must be one of "allof" or "anyof"'); |
|
156 | - } |
|
157 | - } |
|
158 | - |
|
159 | - $newProps['filters'] = []; |
|
160 | - foreach ((array) $elem['value'] as $subElem) { |
|
161 | - if ($subElem['name'] === '{'.Plugin::NS_CARDDAV.'}prop-filter') { |
|
162 | - $newProps['filters'][] = $subElem['value']; |
|
163 | - } |
|
164 | - } |
|
165 | - break; |
|
166 | - case '{'.Plugin::NS_CARDDAV.'}limit': |
|
167 | - foreach ($elem['value'] as $child) { |
|
168 | - if ($child['name'] === '{'.Plugin::NS_CARDDAV.'}nresults') { |
|
169 | - $newProps['limit'] = (int) $child['value']; |
|
170 | - } |
|
171 | - } |
|
172 | - break; |
|
173 | - } |
|
174 | - } |
|
175 | - |
|
176 | - if (is_null($newProps['filters'])) { |
|
177 | - /* |
|
26 | + /** |
|
27 | + * An array with requested properties. |
|
28 | + * |
|
29 | + * @var array |
|
30 | + */ |
|
31 | + public $properties; |
|
32 | + |
|
33 | + /** |
|
34 | + * An array with requested vcard properties. |
|
35 | + * |
|
36 | + * @var array |
|
37 | + */ |
|
38 | + public $addressDataProperties = []; |
|
39 | + |
|
40 | + /** |
|
41 | + * List of property/component filters. |
|
42 | + * |
|
43 | + * This is an array with filters. Every item is a property filter. Every |
|
44 | + * property filter has the following keys: |
|
45 | + * * name - name of the component to filter on |
|
46 | + * * test - anyof or allof |
|
47 | + * * is-not-defined - Test for non-existence |
|
48 | + * * param-filters - A list of parameter filters on the property |
|
49 | + * * text-matches - A list of text values the filter needs to match |
|
50 | + * |
|
51 | + * Each param-filter has the following keys: |
|
52 | + * * name - name of the parameter |
|
53 | + * * is-not-defined - Test for non-existence |
|
54 | + * * text-match - Match the parameter value |
|
55 | + * |
|
56 | + * Each text-match in property filters, and the single text-match in |
|
57 | + * param-filters have the following keys: |
|
58 | + * |
|
59 | + * * value - value to match |
|
60 | + * * match-type - contains, starts-with, ends-with, equals |
|
61 | + * * negate-condition - Do the opposite match |
|
62 | + * * collation - Usually i;unicode-casemap |
|
63 | + * |
|
64 | + * @var array |
|
65 | + */ |
|
66 | + public $filters; |
|
67 | + |
|
68 | + /** |
|
69 | + * The number of results the client wants. |
|
70 | + * |
|
71 | + * null means it wasn't specified, which in most cases means 'all results'. |
|
72 | + * |
|
73 | + * @var int|null |
|
74 | + */ |
|
75 | + public $limit; |
|
76 | + |
|
77 | + /** |
|
78 | + * Either 'anyof' or 'allof'. |
|
79 | + * |
|
80 | + * @var string |
|
81 | + */ |
|
82 | + public $test; |
|
83 | + |
|
84 | + /** |
|
85 | + * The mimetype of the content that should be returend. Usually |
|
86 | + * text/vcard. |
|
87 | + * |
|
88 | + * @var string |
|
89 | + */ |
|
90 | + public $contentType = null; |
|
91 | + |
|
92 | + /** |
|
93 | + * The version of vcard data that should be returned. Usually 3.0, |
|
94 | + * referring to vCard 3.0. |
|
95 | + * |
|
96 | + * @var string |
|
97 | + */ |
|
98 | + public $version = null; |
|
99 | + |
|
100 | + /** |
|
101 | + * The deserialize method is called during xml parsing. |
|
102 | + * |
|
103 | + * This method is called statically, this is because in theory this method |
|
104 | + * may be used as a type of constructor, or factory method. |
|
105 | + * |
|
106 | + * Often you want to return an instance of the current class, but you are |
|
107 | + * free to return other data as well. |
|
108 | + * |
|
109 | + * You are responsible for advancing the reader to the next element. Not |
|
110 | + * doing anything will result in a never-ending loop. |
|
111 | + * |
|
112 | + * If you just want to skip parsing for this element altogether, you can |
|
113 | + * just call $reader->next(); |
|
114 | + * |
|
115 | + * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
116 | + * the next element. |
|
117 | + * |
|
118 | + * @return mixed |
|
119 | + */ |
|
120 | + public static function xmlDeserialize(Reader $reader) |
|
121 | + { |
|
122 | + $elems = (array) $reader->parseInnerTree([ |
|
123 | + '{urn:ietf:params:xml:ns:carddav}prop-filter' => 'Sabre\\CardDAV\\Xml\\Filter\\PropFilter', |
|
124 | + '{urn:ietf:params:xml:ns:carddav}param-filter' => 'Sabre\\CardDAV\\Xml\\Filter\\ParamFilter', |
|
125 | + '{urn:ietf:params:xml:ns:carddav}address-data' => 'Sabre\\CardDAV\\Xml\\Filter\\AddressData', |
|
126 | + '{DAV:}prop' => 'Sabre\\Xml\\Element\\KeyValue', |
|
127 | + ]); |
|
128 | + |
|
129 | + $newProps = [ |
|
130 | + 'filters' => null, |
|
131 | + 'properties' => [], |
|
132 | + 'test' => 'anyof', |
|
133 | + 'limit' => null, |
|
134 | + ]; |
|
135 | + |
|
136 | + if (!is_array($elems)) { |
|
137 | + $elems = []; |
|
138 | + } |
|
139 | + |
|
140 | + foreach ($elems as $elem) { |
|
141 | + switch ($elem['name']) { |
|
142 | + case '{DAV:}prop': |
|
143 | + $newProps['properties'] = array_keys($elem['value']); |
|
144 | + if (isset($elem['value']['{'.Plugin::NS_CARDDAV.'}address-data'])) { |
|
145 | + $newProps += $elem['value']['{'.Plugin::NS_CARDDAV.'}address-data']; |
|
146 | + } |
|
147 | + break; |
|
148 | + case '{'.Plugin::NS_CARDDAV.'}filter': |
|
149 | + if (!is_null($newProps['filters'])) { |
|
150 | + throw new BadRequest('You can only include 1 {'.Plugin::NS_CARDDAV.'}filter element'); |
|
151 | + } |
|
152 | + if (isset($elem['attributes']['test'])) { |
|
153 | + $newProps['test'] = $elem['attributes']['test']; |
|
154 | + if ('allof' !== $newProps['test'] && 'anyof' !== $newProps['test']) { |
|
155 | + throw new BadRequest('The "test" attribute must be one of "allof" or "anyof"'); |
|
156 | + } |
|
157 | + } |
|
158 | + |
|
159 | + $newProps['filters'] = []; |
|
160 | + foreach ((array) $elem['value'] as $subElem) { |
|
161 | + if ($subElem['name'] === '{'.Plugin::NS_CARDDAV.'}prop-filter') { |
|
162 | + $newProps['filters'][] = $subElem['value']; |
|
163 | + } |
|
164 | + } |
|
165 | + break; |
|
166 | + case '{'.Plugin::NS_CARDDAV.'}limit': |
|
167 | + foreach ($elem['value'] as $child) { |
|
168 | + if ($child['name'] === '{'.Plugin::NS_CARDDAV.'}nresults') { |
|
169 | + $newProps['limit'] = (int) $child['value']; |
|
170 | + } |
|
171 | + } |
|
172 | + break; |
|
173 | + } |
|
174 | + } |
|
175 | + |
|
176 | + if (is_null($newProps['filters'])) { |
|
177 | + /* |
|
178 | 178 | * We are supposed to throw this error, but KDE sometimes does not |
179 | 179 | * include the filter element, and we need to treat it as if no |
180 | 180 | * filters are supplied |
181 | 181 | */ |
182 | - //throw new BadRequest('The {' . Plugin::NS_CARDDAV . '}filter element is required for this request'); |
|
183 | - $newProps['filters'] = []; |
|
184 | - } |
|
182 | + //throw new BadRequest('The {' . Plugin::NS_CARDDAV . '}filter element is required for this request'); |
|
183 | + $newProps['filters'] = []; |
|
184 | + } |
|
185 | 185 | |
186 | - $obj = new self(); |
|
187 | - foreach ($newProps as $key => $value) { |
|
188 | - $obj->$key = $value; |
|
189 | - } |
|
186 | + $obj = new self(); |
|
187 | + foreach ($newProps as $key => $value) { |
|
188 | + $obj->$key = $value; |
|
189 | + } |
|
190 | 190 | |
191 | - return $obj; |
|
192 | - } |
|
191 | + return $obj; |
|
192 | + } |
|
193 | 193 | } |
@@ -25,62 +25,62 @@ |
||
25 | 25 | */ |
26 | 26 | abstract class ParamFilter implements Element |
27 | 27 | { |
28 | - /** |
|
29 | - * The deserialize method is called during xml parsing. |
|
30 | - * |
|
31 | - * This method is called statically, this is because in theory this method |
|
32 | - * may be used as a type of constructor, or factory method. |
|
33 | - * |
|
34 | - * Often you want to return an instance of the current class, but you are |
|
35 | - * free to return other data as well. |
|
36 | - * |
|
37 | - * You are responsible for advancing the reader to the next element. Not |
|
38 | - * doing anything will result in a never-ending loop. |
|
39 | - * |
|
40 | - * If you just want to skip parsing for this element altogether, you can |
|
41 | - * just call $reader->next(); |
|
42 | - * |
|
43 | - * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
44 | - * the next element. |
|
45 | - * |
|
46 | - * @return mixed |
|
47 | - */ |
|
48 | - public static function xmlDeserialize(Reader $reader) |
|
49 | - { |
|
50 | - $result = [ |
|
51 | - 'name' => null, |
|
52 | - 'is-not-defined' => false, |
|
53 | - 'text-match' => null, |
|
54 | - ]; |
|
28 | + /** |
|
29 | + * The deserialize method is called during xml parsing. |
|
30 | + * |
|
31 | + * This method is called statically, this is because in theory this method |
|
32 | + * may be used as a type of constructor, or factory method. |
|
33 | + * |
|
34 | + * Often you want to return an instance of the current class, but you are |
|
35 | + * free to return other data as well. |
|
36 | + * |
|
37 | + * You are responsible for advancing the reader to the next element. Not |
|
38 | + * doing anything will result in a never-ending loop. |
|
39 | + * |
|
40 | + * If you just want to skip parsing for this element altogether, you can |
|
41 | + * just call $reader->next(); |
|
42 | + * |
|
43 | + * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
44 | + * the next element. |
|
45 | + * |
|
46 | + * @return mixed |
|
47 | + */ |
|
48 | + public static function xmlDeserialize(Reader $reader) |
|
49 | + { |
|
50 | + $result = [ |
|
51 | + 'name' => null, |
|
52 | + 'is-not-defined' => false, |
|
53 | + 'text-match' => null, |
|
54 | + ]; |
|
55 | 55 | |
56 | - $att = $reader->parseAttributes(); |
|
57 | - $result['name'] = $att['name']; |
|
56 | + $att = $reader->parseAttributes(); |
|
57 | + $result['name'] = $att['name']; |
|
58 | 58 | |
59 | - $elems = $reader->parseInnerTree(); |
|
59 | + $elems = $reader->parseInnerTree(); |
|
60 | 60 | |
61 | - if (is_array($elems)) { |
|
62 | - foreach ($elems as $elem) { |
|
63 | - switch ($elem['name']) { |
|
64 | - case '{'.Plugin::NS_CARDDAV.'}is-not-defined': |
|
65 | - $result['is-not-defined'] = true; |
|
66 | - break; |
|
67 | - case '{'.Plugin::NS_CARDDAV.'}text-match': |
|
68 | - $matchType = isset($elem['attributes']['match-type']) ? $elem['attributes']['match-type'] : 'contains'; |
|
61 | + if (is_array($elems)) { |
|
62 | + foreach ($elems as $elem) { |
|
63 | + switch ($elem['name']) { |
|
64 | + case '{'.Plugin::NS_CARDDAV.'}is-not-defined': |
|
65 | + $result['is-not-defined'] = true; |
|
66 | + break; |
|
67 | + case '{'.Plugin::NS_CARDDAV.'}text-match': |
|
68 | + $matchType = isset($elem['attributes']['match-type']) ? $elem['attributes']['match-type'] : 'contains'; |
|
69 | 69 | |
70 | - if (!in_array($matchType, ['contains', 'equals', 'starts-with', 'ends-with'])) { |
|
71 | - throw new BadRequest('Unknown match-type: '.$matchType); |
|
72 | - } |
|
73 | - $result['text-match'] = [ |
|
74 | - 'negate-condition' => isset($elem['attributes']['negate-condition']) && 'yes' === $elem['attributes']['negate-condition'], |
|
75 | - 'collation' => isset($elem['attributes']['collation']) ? $elem['attributes']['collation'] : 'i;unicode-casemap', |
|
76 | - 'value' => $elem['value'], |
|
77 | - 'match-type' => $matchType, |
|
78 | - ]; |
|
79 | - break; |
|
80 | - } |
|
81 | - } |
|
82 | - } |
|
70 | + if (!in_array($matchType, ['contains', 'equals', 'starts-with', 'ends-with'])) { |
|
71 | + throw new BadRequest('Unknown match-type: '.$matchType); |
|
72 | + } |
|
73 | + $result['text-match'] = [ |
|
74 | + 'negate-condition' => isset($elem['attributes']['negate-condition']) && 'yes' === $elem['attributes']['negate-condition'], |
|
75 | + 'collation' => isset($elem['attributes']['collation']) ? $elem['attributes']['collation'] : 'i;unicode-casemap', |
|
76 | + 'value' => $elem['value'], |
|
77 | + 'match-type' => $matchType, |
|
78 | + ]; |
|
79 | + break; |
|
80 | + } |
|
81 | + } |
|
82 | + } |
|
83 | 83 | |
84 | - return $result; |
|
85 | - } |
|
84 | + return $result; |
|
85 | + } |
|
86 | 86 | } |
@@ -25,71 +25,71 @@ |
||
25 | 25 | */ |
26 | 26 | class PropFilter implements XmlDeserializable |
27 | 27 | { |
28 | - /** |
|
29 | - * The deserialize method is called during xml parsing. |
|
30 | - * |
|
31 | - * This method is called statically, this is because in theory this method |
|
32 | - * may be used as a type of constructor, or factory method. |
|
33 | - * |
|
34 | - * Often you want to return an instance of the current class, but you are |
|
35 | - * free to return other data as well. |
|
36 | - * |
|
37 | - * You are responsible for advancing the reader to the next element. Not |
|
38 | - * doing anything will result in a never-ending loop. |
|
39 | - * |
|
40 | - * If you just want to skip parsing for this element altogether, you can |
|
41 | - * just call $reader->next(); |
|
42 | - * |
|
43 | - * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
44 | - * the next element. |
|
45 | - * |
|
46 | - * @return mixed |
|
47 | - */ |
|
48 | - public static function xmlDeserialize(Reader $reader) |
|
49 | - { |
|
50 | - $result = [ |
|
51 | - 'name' => null, |
|
52 | - 'test' => 'anyof', |
|
53 | - 'is-not-defined' => false, |
|
54 | - 'param-filters' => [], |
|
55 | - 'text-matches' => [], |
|
56 | - ]; |
|
28 | + /** |
|
29 | + * The deserialize method is called during xml parsing. |
|
30 | + * |
|
31 | + * This method is called statically, this is because in theory this method |
|
32 | + * may be used as a type of constructor, or factory method. |
|
33 | + * |
|
34 | + * Often you want to return an instance of the current class, but you are |
|
35 | + * free to return other data as well. |
|
36 | + * |
|
37 | + * You are responsible for advancing the reader to the next element. Not |
|
38 | + * doing anything will result in a never-ending loop. |
|
39 | + * |
|
40 | + * If you just want to skip parsing for this element altogether, you can |
|
41 | + * just call $reader->next(); |
|
42 | + * |
|
43 | + * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
44 | + * the next element. |
|
45 | + * |
|
46 | + * @return mixed |
|
47 | + */ |
|
48 | + public static function xmlDeserialize(Reader $reader) |
|
49 | + { |
|
50 | + $result = [ |
|
51 | + 'name' => null, |
|
52 | + 'test' => 'anyof', |
|
53 | + 'is-not-defined' => false, |
|
54 | + 'param-filters' => [], |
|
55 | + 'text-matches' => [], |
|
56 | + ]; |
|
57 | 57 | |
58 | - $att = $reader->parseAttributes(); |
|
59 | - $result['name'] = $att['name']; |
|
58 | + $att = $reader->parseAttributes(); |
|
59 | + $result['name'] = $att['name']; |
|
60 | 60 | |
61 | - if (isset($att['test']) && 'allof' === $att['test']) { |
|
62 | - $result['test'] = 'allof'; |
|
63 | - } |
|
61 | + if (isset($att['test']) && 'allof' === $att['test']) { |
|
62 | + $result['test'] = 'allof'; |
|
63 | + } |
|
64 | 64 | |
65 | - $elems = $reader->parseInnerTree(); |
|
65 | + $elems = $reader->parseInnerTree(); |
|
66 | 66 | |
67 | - if (is_array($elems)) { |
|
68 | - foreach ($elems as $elem) { |
|
69 | - switch ($elem['name']) { |
|
70 | - case '{'.Plugin::NS_CARDDAV.'}param-filter': |
|
71 | - $result['param-filters'][] = $elem['value']; |
|
72 | - break; |
|
73 | - case '{'.Plugin::NS_CARDDAV.'}is-not-defined': |
|
74 | - $result['is-not-defined'] = true; |
|
75 | - break; |
|
76 | - case '{'.Plugin::NS_CARDDAV.'}text-match': |
|
77 | - $matchType = isset($elem['attributes']['match-type']) ? $elem['attributes']['match-type'] : 'contains'; |
|
67 | + if (is_array($elems)) { |
|
68 | + foreach ($elems as $elem) { |
|
69 | + switch ($elem['name']) { |
|
70 | + case '{'.Plugin::NS_CARDDAV.'}param-filter': |
|
71 | + $result['param-filters'][] = $elem['value']; |
|
72 | + break; |
|
73 | + case '{'.Plugin::NS_CARDDAV.'}is-not-defined': |
|
74 | + $result['is-not-defined'] = true; |
|
75 | + break; |
|
76 | + case '{'.Plugin::NS_CARDDAV.'}text-match': |
|
77 | + $matchType = isset($elem['attributes']['match-type']) ? $elem['attributes']['match-type'] : 'contains'; |
|
78 | 78 | |
79 | - if (!in_array($matchType, ['contains', 'equals', 'starts-with', 'ends-with'])) { |
|
80 | - throw new BadRequest('Unknown match-type: '.$matchType); |
|
81 | - } |
|
82 | - $result['text-matches'][] = [ |
|
83 | - 'negate-condition' => isset($elem['attributes']['negate-condition']) && 'yes' === $elem['attributes']['negate-condition'], |
|
84 | - 'collation' => isset($elem['attributes']['collation']) ? $elem['attributes']['collation'] : 'i;unicode-casemap', |
|
85 | - 'value' => $elem['value'], |
|
86 | - 'match-type' => $matchType, |
|
87 | - ]; |
|
88 | - break; |
|
89 | - } |
|
90 | - } |
|
91 | - } |
|
79 | + if (!in_array($matchType, ['contains', 'equals', 'starts-with', 'ends-with'])) { |
|
80 | + throw new BadRequest('Unknown match-type: '.$matchType); |
|
81 | + } |
|
82 | + $result['text-matches'][] = [ |
|
83 | + 'negate-condition' => isset($elem['attributes']['negate-condition']) && 'yes' === $elem['attributes']['negate-condition'], |
|
84 | + 'collation' => isset($elem['attributes']['collation']) ? $elem['attributes']['collation'] : 'i;unicode-casemap', |
|
85 | + 'value' => $elem['value'], |
|
86 | + 'match-type' => $matchType, |
|
87 | + ]; |
|
88 | + break; |
|
89 | + } |
|
90 | + } |
|
91 | + } |
|
92 | 92 | |
93 | - return $result; |
|
94 | - } |
|
93 | + return $result; |
|
94 | + } |
|
95 | 95 | } |
@@ -25,42 +25,42 @@ |
||
25 | 25 | */ |
26 | 26 | class AddressData implements XmlDeserializable |
27 | 27 | { |
28 | - /** |
|
29 | - * The deserialize method is called during xml parsing. |
|
30 | - * |
|
31 | - * This method is called statically, this is because in theory this method |
|
32 | - * may be used as a type of constructor, or factory method. |
|
33 | - * |
|
34 | - * Often you want to return an instance of the current class, but you are |
|
35 | - * free to return other data as well. |
|
36 | - * |
|
37 | - * You are responsible for advancing the reader to the next element. Not |
|
38 | - * doing anything will result in a never-ending loop. |
|
39 | - * |
|
40 | - * If you just want to skip parsing for this element altogether, you can |
|
41 | - * just call $reader->next(); |
|
42 | - * |
|
43 | - * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
44 | - * the next element. |
|
45 | - * |
|
46 | - * @return mixed |
|
47 | - */ |
|
48 | - public static function xmlDeserialize(Reader $reader) |
|
49 | - { |
|
50 | - $result = [ |
|
51 | - 'contentType' => $reader->getAttribute('content-type') ?: 'text/vcard', |
|
52 | - 'version' => $reader->getAttribute('version') ?: '3.0', |
|
53 | - ]; |
|
28 | + /** |
|
29 | + * The deserialize method is called during xml parsing. |
|
30 | + * |
|
31 | + * This method is called statically, this is because in theory this method |
|
32 | + * may be used as a type of constructor, or factory method. |
|
33 | + * |
|
34 | + * Often you want to return an instance of the current class, but you are |
|
35 | + * free to return other data as well. |
|
36 | + * |
|
37 | + * You are responsible for advancing the reader to the next element. Not |
|
38 | + * doing anything will result in a never-ending loop. |
|
39 | + * |
|
40 | + * If you just want to skip parsing for this element altogether, you can |
|
41 | + * just call $reader->next(); |
|
42 | + * |
|
43 | + * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
44 | + * the next element. |
|
45 | + * |
|
46 | + * @return mixed |
|
47 | + */ |
|
48 | + public static function xmlDeserialize(Reader $reader) |
|
49 | + { |
|
50 | + $result = [ |
|
51 | + 'contentType' => $reader->getAttribute('content-type') ?: 'text/vcard', |
|
52 | + 'version' => $reader->getAttribute('version') ?: '3.0', |
|
53 | + ]; |
|
54 | 54 | |
55 | - $elems = (array) $reader->parseInnerTree(); |
|
56 | - $elems = array_filter($elems, function ($element) { |
|
57 | - return '{urn:ietf:params:xml:ns:carddav}prop' === $element['name'] && |
|
58 | - isset($element['attributes']['name']); |
|
59 | - }); |
|
60 | - $result['addressDataProperties'] = array_map(function ($element) { |
|
61 | - return $element['attributes']['name']; |
|
62 | - }, $elems); |
|
55 | + $elems = (array) $reader->parseInnerTree(); |
|
56 | + $elems = array_filter($elems, function ($element) { |
|
57 | + return '{urn:ietf:params:xml:ns:carddav}prop' === $element['name'] && |
|
58 | + isset($element['attributes']['name']); |
|
59 | + }); |
|
60 | + $result['addressDataProperties'] = array_map(function ($element) { |
|
61 | + return $element['attributes']['name']; |
|
62 | + }, $elems); |
|
63 | 63 | |
64 | - return $result; |
|
65 | - } |
|
64 | + return $result; |
|
65 | + } |
|
66 | 66 | } |
@@ -24,54 +24,54 @@ |
||
24 | 24 | */ |
25 | 25 | class SupportedAddressData implements XmlSerializable |
26 | 26 | { |
27 | - /** |
|
28 | - * supported versions. |
|
29 | - * |
|
30 | - * @var array |
|
31 | - */ |
|
32 | - protected $supportedData = []; |
|
27 | + /** |
|
28 | + * supported versions. |
|
29 | + * |
|
30 | + * @var array |
|
31 | + */ |
|
32 | + protected $supportedData = []; |
|
33 | 33 | |
34 | - /** |
|
35 | - * Creates the property. |
|
36 | - */ |
|
37 | - public function __construct(array $supportedData = null) |
|
38 | - { |
|
39 | - if (is_null($supportedData)) { |
|
40 | - $supportedData = [ |
|
41 | - ['contentType' => 'text/vcard', 'version' => '3.0'], |
|
42 | - ['contentType' => 'text/vcard', 'version' => '4.0'], |
|
43 | - ['contentType' => 'application/vcard+json', 'version' => '4.0'], |
|
44 | - ]; |
|
45 | - } |
|
34 | + /** |
|
35 | + * Creates the property. |
|
36 | + */ |
|
37 | + public function __construct(array $supportedData = null) |
|
38 | + { |
|
39 | + if (is_null($supportedData)) { |
|
40 | + $supportedData = [ |
|
41 | + ['contentType' => 'text/vcard', 'version' => '3.0'], |
|
42 | + ['contentType' => 'text/vcard', 'version' => '4.0'], |
|
43 | + ['contentType' => 'application/vcard+json', 'version' => '4.0'], |
|
44 | + ]; |
|
45 | + } |
|
46 | 46 | |
47 | - $this->supportedData = $supportedData; |
|
48 | - } |
|
47 | + $this->supportedData = $supportedData; |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * The xmlSerialize method is called during xml writing. |
|
52 | - * |
|
53 | - * Use the $writer argument to write its own xml serialization. |
|
54 | - * |
|
55 | - * An important note: do _not_ create a parent element. Any element |
|
56 | - * implementing XmlSerializable should only ever write what's considered |
|
57 | - * its 'inner xml'. |
|
58 | - * |
|
59 | - * The parent of the current element is responsible for writing a |
|
60 | - * containing element. |
|
61 | - * |
|
62 | - * This allows serializers to be re-used for different element names. |
|
63 | - * |
|
64 | - * If you are opening new elements, you must also close them again. |
|
65 | - */ |
|
66 | - public function xmlSerialize(Writer $writer) |
|
67 | - { |
|
68 | - foreach ($this->supportedData as $supported) { |
|
69 | - $writer->startElement('{'.Plugin::NS_CARDDAV.'}address-data-type'); |
|
70 | - $writer->writeAttributes([ |
|
71 | - 'content-type' => $supported['contentType'], |
|
72 | - 'version' => $supported['version'], |
|
73 | - ]); |
|
74 | - $writer->endElement(); // address-data-type |
|
75 | - } |
|
76 | - } |
|
50 | + /** |
|
51 | + * The xmlSerialize method is called during xml writing. |
|
52 | + * |
|
53 | + * Use the $writer argument to write its own xml serialization. |
|
54 | + * |
|
55 | + * An important note: do _not_ create a parent element. Any element |
|
56 | + * implementing XmlSerializable should only ever write what's considered |
|
57 | + * its 'inner xml'. |
|
58 | + * |
|
59 | + * The parent of the current element is responsible for writing a |
|
60 | + * containing element. |
|
61 | + * |
|
62 | + * This allows serializers to be re-used for different element names. |
|
63 | + * |
|
64 | + * If you are opening new elements, you must also close them again. |
|
65 | + */ |
|
66 | + public function xmlSerialize(Writer $writer) |
|
67 | + { |
|
68 | + foreach ($this->supportedData as $supported) { |
|
69 | + $writer->startElement('{'.Plugin::NS_CARDDAV.'}address-data-type'); |
|
70 | + $writer->writeAttributes([ |
|
71 | + 'content-type' => $supported['contentType'], |
|
72 | + 'version' => $supported['version'], |
|
73 | + ]); |
|
74 | + $writer->endElement(); // address-data-type |
|
75 | + } |
|
76 | + } |
|
77 | 77 | } |
@@ -19,26 +19,26 @@ |
||
19 | 19 | */ |
20 | 20 | class SupportedCollationSet implements XmlSerializable |
21 | 21 | { |
22 | - /** |
|
23 | - * The xmlSerialize method is called during xml writing. |
|
24 | - * |
|
25 | - * Use the $writer argument to write its own xml serialization. |
|
26 | - * |
|
27 | - * An important note: do _not_ create a parent element. Any element |
|
28 | - * implementing XmlSerializable should only ever write what's considered |
|
29 | - * its 'inner xml'. |
|
30 | - * |
|
31 | - * The parent of the current element is responsible for writing a |
|
32 | - * containing element. |
|
33 | - * |
|
34 | - * This allows serializers to be re-used for different element names. |
|
35 | - * |
|
36 | - * If you are opening new elements, you must also close them again. |
|
37 | - */ |
|
38 | - public function xmlSerialize(Writer $writer) |
|
39 | - { |
|
40 | - foreach (['i;ascii-casemap', 'i;octet', 'i;unicode-casemap'] as $coll) { |
|
41 | - $writer->writeElement('{urn:ietf:params:xml:ns:carddav}supported-collation', $coll); |
|
42 | - } |
|
43 | - } |
|
22 | + /** |
|
23 | + * The xmlSerialize method is called during xml writing. |
|
24 | + * |
|
25 | + * Use the $writer argument to write its own xml serialization. |
|
26 | + * |
|
27 | + * An important note: do _not_ create a parent element. Any element |
|
28 | + * implementing XmlSerializable should only ever write what's considered |
|
29 | + * its 'inner xml'. |
|
30 | + * |
|
31 | + * The parent of the current element is responsible for writing a |
|
32 | + * containing element. |
|
33 | + * |
|
34 | + * This allows serializers to be re-used for different element names. |
|
35 | + * |
|
36 | + * If you are opening new elements, you must also close them again. |
|
37 | + */ |
|
38 | + public function xmlSerialize(Writer $writer) |
|
39 | + { |
|
40 | + foreach (['i;ascii-casemap', 'i;octet', 'i;unicode-casemap'] as $coll) { |
|
41 | + $writer->writeElement('{urn:ietf:params:xml:ns:carddav}supported-collation', $coll); |
|
42 | + } |
|
43 | + } |
|
44 | 44 | } |
@@ -20,159 +20,159 @@ |
||
20 | 20 | */ |
21 | 21 | class AddressBookHome extends DAV\Collection implements DAV\IExtendedCollection, DAVACL\IACL |
22 | 22 | { |
23 | - use DAVACL\ACLTrait; |
|
24 | - |
|
25 | - /** |
|
26 | - * Principal uri. |
|
27 | - * |
|
28 | - * @var array |
|
29 | - */ |
|
30 | - protected $principalUri; |
|
31 | - |
|
32 | - /** |
|
33 | - * carddavBackend. |
|
34 | - * |
|
35 | - * @var Backend\BackendInterface |
|
36 | - */ |
|
37 | - protected $carddavBackend; |
|
38 | - |
|
39 | - /** |
|
40 | - * Constructor. |
|
41 | - * |
|
42 | - * @param string $principalUri |
|
43 | - */ |
|
44 | - public function __construct(Backend\BackendInterface $carddavBackend, $principalUri) |
|
45 | - { |
|
46 | - $this->carddavBackend = $carddavBackend; |
|
47 | - $this->principalUri = $principalUri; |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * Returns the name of this object. |
|
52 | - * |
|
53 | - * @return string |
|
54 | - */ |
|
55 | - public function getName() |
|
56 | - { |
|
57 | - list(, $name) = Uri\split($this->principalUri); |
|
58 | - |
|
59 | - return $name; |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * Updates the name of this object. |
|
64 | - * |
|
65 | - * @param string $name |
|
66 | - */ |
|
67 | - public function setName($name) |
|
68 | - { |
|
69 | - throw new DAV\Exception\MethodNotAllowed(); |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * Deletes this object. |
|
74 | - */ |
|
75 | - public function delete() |
|
76 | - { |
|
77 | - throw new DAV\Exception\MethodNotAllowed(); |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * Returns the last modification date. |
|
82 | - * |
|
83 | - * @return int |
|
84 | - */ |
|
85 | - public function getLastModified() |
|
86 | - { |
|
87 | - return null; |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Creates a new file under this object. |
|
92 | - * |
|
93 | - * This is currently not allowed |
|
94 | - * |
|
95 | - * @param string $filename |
|
96 | - * @param resource $data |
|
97 | - */ |
|
98 | - public function createFile($filename, $data = null) |
|
99 | - { |
|
100 | - throw new DAV\Exception\MethodNotAllowed('Creating new files in this collection is not supported'); |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Creates a new directory under this object. |
|
105 | - * |
|
106 | - * This is currently not allowed. |
|
107 | - * |
|
108 | - * @param string $filename |
|
109 | - */ |
|
110 | - public function createDirectory($filename) |
|
111 | - { |
|
112 | - throw new DAV\Exception\MethodNotAllowed('Creating new collections in this collection is not supported'); |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * Returns a single addressbook, by name. |
|
117 | - * |
|
118 | - * @param string $name |
|
119 | - * |
|
120 | - * @todo needs optimizing |
|
121 | - * |
|
122 | - * @return AddressBook |
|
123 | - */ |
|
124 | - public function getChild($name) |
|
125 | - { |
|
126 | - foreach ($this->getChildren() as $child) { |
|
127 | - if ($name == $child->getName()) { |
|
128 | - return $child; |
|
129 | - } |
|
130 | - } |
|
131 | - throw new DAV\Exception\NotFound('Addressbook with name \''.$name.'\' could not be found'); |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * Returns a list of addressbooks. |
|
136 | - * |
|
137 | - * @return array |
|
138 | - */ |
|
139 | - public function getChildren() |
|
140 | - { |
|
141 | - $addressbooks = $this->carddavBackend->getAddressBooksForUser($this->principalUri); |
|
142 | - $objs = []; |
|
143 | - foreach ($addressbooks as $addressbook) { |
|
144 | - $objs[] = new AddressBook($this->carddavBackend, $addressbook); |
|
145 | - } |
|
146 | - |
|
147 | - return $objs; |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * Creates a new address book. |
|
152 | - * |
|
153 | - * @param string $name |
|
154 | - * |
|
155 | - * @throws DAV\Exception\InvalidResourceType |
|
156 | - */ |
|
157 | - public function createExtendedCollection($name, MkCol $mkCol) |
|
158 | - { |
|
159 | - if (!$mkCol->hasResourceType('{'.Plugin::NS_CARDDAV.'}addressbook')) { |
|
160 | - throw new DAV\Exception\InvalidResourceType('Unknown resourceType for this collection'); |
|
161 | - } |
|
162 | - $properties = $mkCol->getRemainingValues(); |
|
163 | - $mkCol->setRemainingResultCode(201); |
|
164 | - $this->carddavBackend->createAddressBook($this->principalUri, $name, $properties); |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Returns the owner principal. |
|
169 | - * |
|
170 | - * This must be a url to a principal, or null if there's no owner |
|
171 | - * |
|
172 | - * @return string|null |
|
173 | - */ |
|
174 | - public function getOwner() |
|
175 | - { |
|
176 | - return $this->principalUri; |
|
177 | - } |
|
23 | + use DAVACL\ACLTrait; |
|
24 | + |
|
25 | + /** |
|
26 | + * Principal uri. |
|
27 | + * |
|
28 | + * @var array |
|
29 | + */ |
|
30 | + protected $principalUri; |
|
31 | + |
|
32 | + /** |
|
33 | + * carddavBackend. |
|
34 | + * |
|
35 | + * @var Backend\BackendInterface |
|
36 | + */ |
|
37 | + protected $carddavBackend; |
|
38 | + |
|
39 | + /** |
|
40 | + * Constructor. |
|
41 | + * |
|
42 | + * @param string $principalUri |
|
43 | + */ |
|
44 | + public function __construct(Backend\BackendInterface $carddavBackend, $principalUri) |
|
45 | + { |
|
46 | + $this->carddavBackend = $carddavBackend; |
|
47 | + $this->principalUri = $principalUri; |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * Returns the name of this object. |
|
52 | + * |
|
53 | + * @return string |
|
54 | + */ |
|
55 | + public function getName() |
|
56 | + { |
|
57 | + list(, $name) = Uri\split($this->principalUri); |
|
58 | + |
|
59 | + return $name; |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * Updates the name of this object. |
|
64 | + * |
|
65 | + * @param string $name |
|
66 | + */ |
|
67 | + public function setName($name) |
|
68 | + { |
|
69 | + throw new DAV\Exception\MethodNotAllowed(); |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * Deletes this object. |
|
74 | + */ |
|
75 | + public function delete() |
|
76 | + { |
|
77 | + throw new DAV\Exception\MethodNotAllowed(); |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * Returns the last modification date. |
|
82 | + * |
|
83 | + * @return int |
|
84 | + */ |
|
85 | + public function getLastModified() |
|
86 | + { |
|
87 | + return null; |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Creates a new file under this object. |
|
92 | + * |
|
93 | + * This is currently not allowed |
|
94 | + * |
|
95 | + * @param string $filename |
|
96 | + * @param resource $data |
|
97 | + */ |
|
98 | + public function createFile($filename, $data = null) |
|
99 | + { |
|
100 | + throw new DAV\Exception\MethodNotAllowed('Creating new files in this collection is not supported'); |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Creates a new directory under this object. |
|
105 | + * |
|
106 | + * This is currently not allowed. |
|
107 | + * |
|
108 | + * @param string $filename |
|
109 | + */ |
|
110 | + public function createDirectory($filename) |
|
111 | + { |
|
112 | + throw new DAV\Exception\MethodNotAllowed('Creating new collections in this collection is not supported'); |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * Returns a single addressbook, by name. |
|
117 | + * |
|
118 | + * @param string $name |
|
119 | + * |
|
120 | + * @todo needs optimizing |
|
121 | + * |
|
122 | + * @return AddressBook |
|
123 | + */ |
|
124 | + public function getChild($name) |
|
125 | + { |
|
126 | + foreach ($this->getChildren() as $child) { |
|
127 | + if ($name == $child->getName()) { |
|
128 | + return $child; |
|
129 | + } |
|
130 | + } |
|
131 | + throw new DAV\Exception\NotFound('Addressbook with name \''.$name.'\' could not be found'); |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * Returns a list of addressbooks. |
|
136 | + * |
|
137 | + * @return array |
|
138 | + */ |
|
139 | + public function getChildren() |
|
140 | + { |
|
141 | + $addressbooks = $this->carddavBackend->getAddressBooksForUser($this->principalUri); |
|
142 | + $objs = []; |
|
143 | + foreach ($addressbooks as $addressbook) { |
|
144 | + $objs[] = new AddressBook($this->carddavBackend, $addressbook); |
|
145 | + } |
|
146 | + |
|
147 | + return $objs; |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * Creates a new address book. |
|
152 | + * |
|
153 | + * @param string $name |
|
154 | + * |
|
155 | + * @throws DAV\Exception\InvalidResourceType |
|
156 | + */ |
|
157 | + public function createExtendedCollection($name, MkCol $mkCol) |
|
158 | + { |
|
159 | + if (!$mkCol->hasResourceType('{'.Plugin::NS_CARDDAV.'}addressbook')) { |
|
160 | + throw new DAV\Exception\InvalidResourceType('Unknown resourceType for this collection'); |
|
161 | + } |
|
162 | + $properties = $mkCol->getRemainingValues(); |
|
163 | + $mkCol->setRemainingResultCode(201); |
|
164 | + $this->carddavBackend->createAddressBook($this->principalUri, $name, $properties); |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * Returns the owner principal. |
|
169 | + * |
|
170 | + * This must be a url to a principal, or null if there's no owner |
|
171 | + * |
|
172 | + * @return string|null |
|
173 | + */ |
|
174 | + public function getOwner() |
|
175 | + { |
|
176 | + return $this->principalUri; |
|
177 | + } |
|
178 | 178 | } |
@@ -16,187 +16,187 @@ |
||
16 | 16 | */ |
17 | 17 | class Card extends DAV\File implements ICard, DAVACL\IACL |
18 | 18 | { |
19 | - use DAVACL\ACLTrait; |
|
20 | - |
|
21 | - /** |
|
22 | - * CardDAV backend. |
|
23 | - * |
|
24 | - * @var Backend\BackendInterface |
|
25 | - */ |
|
26 | - protected $carddavBackend; |
|
27 | - |
|
28 | - /** |
|
29 | - * Array with information about this Card. |
|
30 | - * |
|
31 | - * @var array |
|
32 | - */ |
|
33 | - protected $cardData; |
|
34 | - |
|
35 | - /** |
|
36 | - * Array with information about the containing addressbook. |
|
37 | - * |
|
38 | - * @var array |
|
39 | - */ |
|
40 | - protected $addressBookInfo; |
|
41 | - |
|
42 | - /** |
|
43 | - * Constructor. |
|
44 | - */ |
|
45 | - public function __construct(Backend\BackendInterface $carddavBackend, array $addressBookInfo, array $cardData) |
|
46 | - { |
|
47 | - $this->carddavBackend = $carddavBackend; |
|
48 | - $this->addressBookInfo = $addressBookInfo; |
|
49 | - $this->cardData = $cardData; |
|
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * Returns the uri for this object. |
|
54 | - * |
|
55 | - * @return string |
|
56 | - */ |
|
57 | - public function getName() |
|
58 | - { |
|
59 | - return $this->cardData['uri']; |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * Returns the VCard-formatted object. |
|
64 | - * |
|
65 | - * @return string |
|
66 | - */ |
|
67 | - public function get() |
|
68 | - { |
|
69 | - // Pre-populating 'carddata' is optional. If we don't yet have it |
|
70 | - // already, we fetch it from the backend. |
|
71 | - if (!isset($this->cardData['carddata'])) { |
|
72 | - $this->cardData = $this->carddavBackend->getCard($this->addressBookInfo['id'], $this->cardData['uri']); |
|
73 | - } |
|
74 | - |
|
75 | - return $this->cardData['carddata']; |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * Updates the VCard-formatted object. |
|
80 | - * |
|
81 | - * @param string $cardData |
|
82 | - * |
|
83 | - * @return string|null |
|
84 | - */ |
|
85 | - public function put($cardData) |
|
86 | - { |
|
87 | - if (is_resource($cardData)) { |
|
88 | - $cardData = stream_get_contents($cardData); |
|
89 | - } |
|
90 | - |
|
91 | - // Converting to UTF-8, if needed |
|
92 | - $cardData = DAV\StringUtil::ensureUTF8($cardData); |
|
93 | - |
|
94 | - $etag = $this->carddavBackend->updateCard($this->addressBookInfo['id'], $this->cardData['uri'], $cardData); |
|
95 | - $this->cardData['carddata'] = $cardData; |
|
96 | - $this->cardData['etag'] = $etag; |
|
97 | - |
|
98 | - return $etag; |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * Deletes the card. |
|
103 | - */ |
|
104 | - public function delete() |
|
105 | - { |
|
106 | - $this->carddavBackend->deleteCard($this->addressBookInfo['id'], $this->cardData['uri']); |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Returns the mime content-type. |
|
111 | - * |
|
112 | - * @return string |
|
113 | - */ |
|
114 | - public function getContentType() |
|
115 | - { |
|
116 | - return 'text/vcard; charset=utf-8'; |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * Returns an ETag for this object. |
|
121 | - * |
|
122 | - * @return string |
|
123 | - */ |
|
124 | - public function getETag() |
|
125 | - { |
|
126 | - if (isset($this->cardData['etag'])) { |
|
127 | - return $this->cardData['etag']; |
|
128 | - } else { |
|
129 | - $data = $this->get(); |
|
130 | - if (is_string($data)) { |
|
131 | - return '"'.md5($data).'"'; |
|
132 | - } else { |
|
133 | - // We refuse to calculate the md5 if it's a stream. |
|
134 | - return null; |
|
135 | - } |
|
136 | - } |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * Returns the last modification date as a unix timestamp. |
|
141 | - * |
|
142 | - * @return int |
|
143 | - */ |
|
144 | - public function getLastModified() |
|
145 | - { |
|
146 | - return isset($this->cardData['lastmodified']) ? $this->cardData['lastmodified'] : null; |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * Returns the size of this object in bytes. |
|
151 | - * |
|
152 | - * @return int |
|
153 | - */ |
|
154 | - public function getSize() |
|
155 | - { |
|
156 | - if (array_key_exists('size', $this->cardData)) { |
|
157 | - return $this->cardData['size']; |
|
158 | - } else { |
|
159 | - return strlen($this->get()); |
|
160 | - } |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * Returns the owner principal. |
|
165 | - * |
|
166 | - * This must be a url to a principal, or null if there's no owner |
|
167 | - * |
|
168 | - * @return string|null |
|
169 | - */ |
|
170 | - public function getOwner() |
|
171 | - { |
|
172 | - return $this->addressBookInfo['principaluri']; |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * Returns a list of ACE's for this node. |
|
177 | - * |
|
178 | - * Each ACE has the following properties: |
|
179 | - * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are |
|
180 | - * currently the only supported privileges |
|
181 | - * * 'principal', a url to the principal who owns the node |
|
182 | - * * 'protected' (optional), indicating that this ACE is not allowed to |
|
183 | - * be updated. |
|
184 | - * |
|
185 | - * @return array |
|
186 | - */ |
|
187 | - public function getACL() |
|
188 | - { |
|
189 | - // An alternative acl may be specified through the cardData array. |
|
190 | - if (isset($this->cardData['acl'])) { |
|
191 | - return $this->cardData['acl']; |
|
192 | - } |
|
193 | - |
|
194 | - return [ |
|
195 | - [ |
|
196 | - 'privilege' => '{DAV:}all', |
|
197 | - 'principal' => $this->addressBookInfo['principaluri'], |
|
198 | - 'protected' => true, |
|
199 | - ], |
|
200 | - ]; |
|
201 | - } |
|
19 | + use DAVACL\ACLTrait; |
|
20 | + |
|
21 | + /** |
|
22 | + * CardDAV backend. |
|
23 | + * |
|
24 | + * @var Backend\BackendInterface |
|
25 | + */ |
|
26 | + protected $carddavBackend; |
|
27 | + |
|
28 | + /** |
|
29 | + * Array with information about this Card. |
|
30 | + * |
|
31 | + * @var array |
|
32 | + */ |
|
33 | + protected $cardData; |
|
34 | + |
|
35 | + /** |
|
36 | + * Array with information about the containing addressbook. |
|
37 | + * |
|
38 | + * @var array |
|
39 | + */ |
|
40 | + protected $addressBookInfo; |
|
41 | + |
|
42 | + /** |
|
43 | + * Constructor. |
|
44 | + */ |
|
45 | + public function __construct(Backend\BackendInterface $carddavBackend, array $addressBookInfo, array $cardData) |
|
46 | + { |
|
47 | + $this->carddavBackend = $carddavBackend; |
|
48 | + $this->addressBookInfo = $addressBookInfo; |
|
49 | + $this->cardData = $cardData; |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * Returns the uri for this object. |
|
54 | + * |
|
55 | + * @return string |
|
56 | + */ |
|
57 | + public function getName() |
|
58 | + { |
|
59 | + return $this->cardData['uri']; |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * Returns the VCard-formatted object. |
|
64 | + * |
|
65 | + * @return string |
|
66 | + */ |
|
67 | + public function get() |
|
68 | + { |
|
69 | + // Pre-populating 'carddata' is optional. If we don't yet have it |
|
70 | + // already, we fetch it from the backend. |
|
71 | + if (!isset($this->cardData['carddata'])) { |
|
72 | + $this->cardData = $this->carddavBackend->getCard($this->addressBookInfo['id'], $this->cardData['uri']); |
|
73 | + } |
|
74 | + |
|
75 | + return $this->cardData['carddata']; |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * Updates the VCard-formatted object. |
|
80 | + * |
|
81 | + * @param string $cardData |
|
82 | + * |
|
83 | + * @return string|null |
|
84 | + */ |
|
85 | + public function put($cardData) |
|
86 | + { |
|
87 | + if (is_resource($cardData)) { |
|
88 | + $cardData = stream_get_contents($cardData); |
|
89 | + } |
|
90 | + |
|
91 | + // Converting to UTF-8, if needed |
|
92 | + $cardData = DAV\StringUtil::ensureUTF8($cardData); |
|
93 | + |
|
94 | + $etag = $this->carddavBackend->updateCard($this->addressBookInfo['id'], $this->cardData['uri'], $cardData); |
|
95 | + $this->cardData['carddata'] = $cardData; |
|
96 | + $this->cardData['etag'] = $etag; |
|
97 | + |
|
98 | + return $etag; |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * Deletes the card. |
|
103 | + */ |
|
104 | + public function delete() |
|
105 | + { |
|
106 | + $this->carddavBackend->deleteCard($this->addressBookInfo['id'], $this->cardData['uri']); |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Returns the mime content-type. |
|
111 | + * |
|
112 | + * @return string |
|
113 | + */ |
|
114 | + public function getContentType() |
|
115 | + { |
|
116 | + return 'text/vcard; charset=utf-8'; |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * Returns an ETag for this object. |
|
121 | + * |
|
122 | + * @return string |
|
123 | + */ |
|
124 | + public function getETag() |
|
125 | + { |
|
126 | + if (isset($this->cardData['etag'])) { |
|
127 | + return $this->cardData['etag']; |
|
128 | + } else { |
|
129 | + $data = $this->get(); |
|
130 | + if (is_string($data)) { |
|
131 | + return '"'.md5($data).'"'; |
|
132 | + } else { |
|
133 | + // We refuse to calculate the md5 if it's a stream. |
|
134 | + return null; |
|
135 | + } |
|
136 | + } |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * Returns the last modification date as a unix timestamp. |
|
141 | + * |
|
142 | + * @return int |
|
143 | + */ |
|
144 | + public function getLastModified() |
|
145 | + { |
|
146 | + return isset($this->cardData['lastmodified']) ? $this->cardData['lastmodified'] : null; |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * Returns the size of this object in bytes. |
|
151 | + * |
|
152 | + * @return int |
|
153 | + */ |
|
154 | + public function getSize() |
|
155 | + { |
|
156 | + if (array_key_exists('size', $this->cardData)) { |
|
157 | + return $this->cardData['size']; |
|
158 | + } else { |
|
159 | + return strlen($this->get()); |
|
160 | + } |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * Returns the owner principal. |
|
165 | + * |
|
166 | + * This must be a url to a principal, or null if there's no owner |
|
167 | + * |
|
168 | + * @return string|null |
|
169 | + */ |
|
170 | + public function getOwner() |
|
171 | + { |
|
172 | + return $this->addressBookInfo['principaluri']; |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * Returns a list of ACE's for this node. |
|
177 | + * |
|
178 | + * Each ACE has the following properties: |
|
179 | + * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are |
|
180 | + * currently the only supported privileges |
|
181 | + * * 'principal', a url to the principal who owns the node |
|
182 | + * * 'protected' (optional), indicating that this ACE is not allowed to |
|
183 | + * be updated. |
|
184 | + * |
|
185 | + * @return array |
|
186 | + */ |
|
187 | + public function getACL() |
|
188 | + { |
|
189 | + // An alternative acl may be specified through the cardData array. |
|
190 | + if (isset($this->cardData['acl'])) { |
|
191 | + return $this->cardData['acl']; |
|
192 | + } |
|
193 | + |
|
194 | + return [ |
|
195 | + [ |
|
196 | + 'privilege' => '{DAV:}all', |
|
197 | + 'principal' => $this->addressBookInfo['principaluri'], |
|
198 | + 'protected' => true, |
|
199 | + ], |
|
200 | + ]; |
|
201 | + } |
|
202 | 202 | } |
@@ -18,318 +18,318 @@ |
||
18 | 18 | */ |
19 | 19 | class AddressBook extends DAV\Collection implements IAddressBook, DAV\IProperties, DAVACL\IACL, DAV\Sync\ISyncCollection, DAV\IMultiGet |
20 | 20 | { |
21 | - use DAVACL\ACLTrait; |
|
21 | + use DAVACL\ACLTrait; |
|
22 | 22 | |
23 | - /** |
|
24 | - * This is an array with addressbook information. |
|
25 | - * |
|
26 | - * @var array |
|
27 | - */ |
|
28 | - protected $addressBookInfo; |
|
23 | + /** |
|
24 | + * This is an array with addressbook information. |
|
25 | + * |
|
26 | + * @var array |
|
27 | + */ |
|
28 | + protected $addressBookInfo; |
|
29 | 29 | |
30 | - /** |
|
31 | - * CardDAV backend. |
|
32 | - * |
|
33 | - * @var Backend\BackendInterface |
|
34 | - */ |
|
35 | - protected $carddavBackend; |
|
30 | + /** |
|
31 | + * CardDAV backend. |
|
32 | + * |
|
33 | + * @var Backend\BackendInterface |
|
34 | + */ |
|
35 | + protected $carddavBackend; |
|
36 | 36 | |
37 | - /** |
|
38 | - * Constructor. |
|
39 | - */ |
|
40 | - public function __construct(Backend\BackendInterface $carddavBackend, array $addressBookInfo) |
|
41 | - { |
|
42 | - $this->carddavBackend = $carddavBackend; |
|
43 | - $this->addressBookInfo = $addressBookInfo; |
|
44 | - } |
|
37 | + /** |
|
38 | + * Constructor. |
|
39 | + */ |
|
40 | + public function __construct(Backend\BackendInterface $carddavBackend, array $addressBookInfo) |
|
41 | + { |
|
42 | + $this->carddavBackend = $carddavBackend; |
|
43 | + $this->addressBookInfo = $addressBookInfo; |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * Returns the name of the addressbook. |
|
48 | - * |
|
49 | - * @return string |
|
50 | - */ |
|
51 | - public function getName() |
|
52 | - { |
|
53 | - return $this->addressBookInfo['uri']; |
|
54 | - } |
|
46 | + /** |
|
47 | + * Returns the name of the addressbook. |
|
48 | + * |
|
49 | + * @return string |
|
50 | + */ |
|
51 | + public function getName() |
|
52 | + { |
|
53 | + return $this->addressBookInfo['uri']; |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * Returns a card. |
|
58 | - * |
|
59 | - * @param string $name |
|
60 | - * |
|
61 | - * @return Card |
|
62 | - */ |
|
63 | - public function getChild($name) |
|
64 | - { |
|
65 | - $obj = $this->carddavBackend->getCard($this->addressBookInfo['id'], $name); |
|
66 | - if (!$obj) { |
|
67 | - throw new DAV\Exception\NotFound('Card not found'); |
|
68 | - } |
|
56 | + /** |
|
57 | + * Returns a card. |
|
58 | + * |
|
59 | + * @param string $name |
|
60 | + * |
|
61 | + * @return Card |
|
62 | + */ |
|
63 | + public function getChild($name) |
|
64 | + { |
|
65 | + $obj = $this->carddavBackend->getCard($this->addressBookInfo['id'], $name); |
|
66 | + if (!$obj) { |
|
67 | + throw new DAV\Exception\NotFound('Card not found'); |
|
68 | + } |
|
69 | 69 | |
70 | - return new Card($this->carddavBackend, $this->addressBookInfo, $obj); |
|
71 | - } |
|
70 | + return new Card($this->carddavBackend, $this->addressBookInfo, $obj); |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * Returns the full list of cards. |
|
75 | - * |
|
76 | - * @return array |
|
77 | - */ |
|
78 | - public function getChildren() |
|
79 | - { |
|
80 | - $objs = $this->carddavBackend->getCards($this->addressBookInfo['id']); |
|
81 | - $children = []; |
|
82 | - foreach ($objs as $obj) { |
|
83 | - $obj['acl'] = $this->getChildACL(); |
|
84 | - $children[] = new Card($this->carddavBackend, $this->addressBookInfo, $obj); |
|
85 | - } |
|
73 | + /** |
|
74 | + * Returns the full list of cards. |
|
75 | + * |
|
76 | + * @return array |
|
77 | + */ |
|
78 | + public function getChildren() |
|
79 | + { |
|
80 | + $objs = $this->carddavBackend->getCards($this->addressBookInfo['id']); |
|
81 | + $children = []; |
|
82 | + foreach ($objs as $obj) { |
|
83 | + $obj['acl'] = $this->getChildACL(); |
|
84 | + $children[] = new Card($this->carddavBackend, $this->addressBookInfo, $obj); |
|
85 | + } |
|
86 | 86 | |
87 | - return $children; |
|
88 | - } |
|
87 | + return $children; |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * This method receives a list of paths in it's first argument. |
|
92 | - * It must return an array with Node objects. |
|
93 | - * |
|
94 | - * If any children are not found, you do not have to return them. |
|
95 | - * |
|
96 | - * @param string[] $paths |
|
97 | - * |
|
98 | - * @return array |
|
99 | - */ |
|
100 | - public function getMultipleChildren(array $paths) |
|
101 | - { |
|
102 | - $objs = $this->carddavBackend->getMultipleCards($this->addressBookInfo['id'], $paths); |
|
103 | - $children = []; |
|
104 | - foreach ($objs as $obj) { |
|
105 | - $obj['acl'] = $this->getChildACL(); |
|
106 | - $children[] = new Card($this->carddavBackend, $this->addressBookInfo, $obj); |
|
107 | - } |
|
90 | + /** |
|
91 | + * This method receives a list of paths in it's first argument. |
|
92 | + * It must return an array with Node objects. |
|
93 | + * |
|
94 | + * If any children are not found, you do not have to return them. |
|
95 | + * |
|
96 | + * @param string[] $paths |
|
97 | + * |
|
98 | + * @return array |
|
99 | + */ |
|
100 | + public function getMultipleChildren(array $paths) |
|
101 | + { |
|
102 | + $objs = $this->carddavBackend->getMultipleCards($this->addressBookInfo['id'], $paths); |
|
103 | + $children = []; |
|
104 | + foreach ($objs as $obj) { |
|
105 | + $obj['acl'] = $this->getChildACL(); |
|
106 | + $children[] = new Card($this->carddavBackend, $this->addressBookInfo, $obj); |
|
107 | + } |
|
108 | 108 | |
109 | - return $children; |
|
110 | - } |
|
109 | + return $children; |
|
110 | + } |
|
111 | 111 | |
112 | - /** |
|
113 | - * Creates a new directory. |
|
114 | - * |
|
115 | - * We actually block this, as subdirectories are not allowed in addressbooks. |
|
116 | - * |
|
117 | - * @param string $name |
|
118 | - */ |
|
119 | - public function createDirectory($name) |
|
120 | - { |
|
121 | - throw new DAV\Exception\MethodNotAllowed('Creating collections in addressbooks is not allowed'); |
|
122 | - } |
|
112 | + /** |
|
113 | + * Creates a new directory. |
|
114 | + * |
|
115 | + * We actually block this, as subdirectories are not allowed in addressbooks. |
|
116 | + * |
|
117 | + * @param string $name |
|
118 | + */ |
|
119 | + public function createDirectory($name) |
|
120 | + { |
|
121 | + throw new DAV\Exception\MethodNotAllowed('Creating collections in addressbooks is not allowed'); |
|
122 | + } |
|
123 | 123 | |
124 | - /** |
|
125 | - * Creates a new file. |
|
126 | - * |
|
127 | - * The contents of the new file must be a valid VCARD. |
|
128 | - * |
|
129 | - * This method may return an ETag. |
|
130 | - * |
|
131 | - * @param string $name |
|
132 | - * @param resource $vcardData |
|
133 | - * |
|
134 | - * @return string|null |
|
135 | - */ |
|
136 | - public function createFile($name, $vcardData = null) |
|
137 | - { |
|
138 | - if (is_resource($vcardData)) { |
|
139 | - $vcardData = stream_get_contents($vcardData); |
|
140 | - } |
|
141 | - // Converting to UTF-8, if needed |
|
142 | - $vcardData = DAV\StringUtil::ensureUTF8($vcardData); |
|
124 | + /** |
|
125 | + * Creates a new file. |
|
126 | + * |
|
127 | + * The contents of the new file must be a valid VCARD. |
|
128 | + * |
|
129 | + * This method may return an ETag. |
|
130 | + * |
|
131 | + * @param string $name |
|
132 | + * @param resource $vcardData |
|
133 | + * |
|
134 | + * @return string|null |
|
135 | + */ |
|
136 | + public function createFile($name, $vcardData = null) |
|
137 | + { |
|
138 | + if (is_resource($vcardData)) { |
|
139 | + $vcardData = stream_get_contents($vcardData); |
|
140 | + } |
|
141 | + // Converting to UTF-8, if needed |
|
142 | + $vcardData = DAV\StringUtil::ensureUTF8($vcardData); |
|
143 | 143 | |
144 | - return $this->carddavBackend->createCard($this->addressBookInfo['id'], $name, $vcardData); |
|
145 | - } |
|
144 | + return $this->carddavBackend->createCard($this->addressBookInfo['id'], $name, $vcardData); |
|
145 | + } |
|
146 | 146 | |
147 | - /** |
|
148 | - * Deletes the entire addressbook. |
|
149 | - */ |
|
150 | - public function delete() |
|
151 | - { |
|
152 | - $this->carddavBackend->deleteAddressBook($this->addressBookInfo['id']); |
|
153 | - } |
|
147 | + /** |
|
148 | + * Deletes the entire addressbook. |
|
149 | + */ |
|
150 | + public function delete() |
|
151 | + { |
|
152 | + $this->carddavBackend->deleteAddressBook($this->addressBookInfo['id']); |
|
153 | + } |
|
154 | 154 | |
155 | - /** |
|
156 | - * Renames the addressbook. |
|
157 | - * |
|
158 | - * @param string $newName |
|
159 | - */ |
|
160 | - public function setName($newName) |
|
161 | - { |
|
162 | - throw new DAV\Exception\MethodNotAllowed('Renaming addressbooks is not yet supported'); |
|
163 | - } |
|
155 | + /** |
|
156 | + * Renames the addressbook. |
|
157 | + * |
|
158 | + * @param string $newName |
|
159 | + */ |
|
160 | + public function setName($newName) |
|
161 | + { |
|
162 | + throw new DAV\Exception\MethodNotAllowed('Renaming addressbooks is not yet supported'); |
|
163 | + } |
|
164 | 164 | |
165 | - /** |
|
166 | - * Returns the last modification date as a unix timestamp. |
|
167 | - */ |
|
168 | - public function getLastModified() |
|
169 | - { |
|
170 | - return null; |
|
171 | - } |
|
165 | + /** |
|
166 | + * Returns the last modification date as a unix timestamp. |
|
167 | + */ |
|
168 | + public function getLastModified() |
|
169 | + { |
|
170 | + return null; |
|
171 | + } |
|
172 | 172 | |
173 | - /** |
|
174 | - * Updates properties on this node. |
|
175 | - * |
|
176 | - * This method received a PropPatch object, which contains all the |
|
177 | - * information about the update. |
|
178 | - * |
|
179 | - * To update specific properties, call the 'handle' method on this object. |
|
180 | - * Read the PropPatch documentation for more information. |
|
181 | - */ |
|
182 | - public function propPatch(DAV\PropPatch $propPatch) |
|
183 | - { |
|
184 | - return $this->carddavBackend->updateAddressBook($this->addressBookInfo['id'], $propPatch); |
|
185 | - } |
|
173 | + /** |
|
174 | + * Updates properties on this node. |
|
175 | + * |
|
176 | + * This method received a PropPatch object, which contains all the |
|
177 | + * information about the update. |
|
178 | + * |
|
179 | + * To update specific properties, call the 'handle' method on this object. |
|
180 | + * Read the PropPatch documentation for more information. |
|
181 | + */ |
|
182 | + public function propPatch(DAV\PropPatch $propPatch) |
|
183 | + { |
|
184 | + return $this->carddavBackend->updateAddressBook($this->addressBookInfo['id'], $propPatch); |
|
185 | + } |
|
186 | 186 | |
187 | - /** |
|
188 | - * Returns a list of properties for this nodes. |
|
189 | - * |
|
190 | - * The properties list is a list of propertynames the client requested, |
|
191 | - * encoded in clark-notation {xmlnamespace}tagname |
|
192 | - * |
|
193 | - * If the array is empty, it means 'all properties' were requested. |
|
194 | - * |
|
195 | - * @param array $properties |
|
196 | - * |
|
197 | - * @return array |
|
198 | - */ |
|
199 | - public function getProperties($properties) |
|
200 | - { |
|
201 | - $response = []; |
|
202 | - foreach ($properties as $propertyName) { |
|
203 | - if (isset($this->addressBookInfo[$propertyName])) { |
|
204 | - $response[$propertyName] = $this->addressBookInfo[$propertyName]; |
|
205 | - } |
|
206 | - } |
|
187 | + /** |
|
188 | + * Returns a list of properties for this nodes. |
|
189 | + * |
|
190 | + * The properties list is a list of propertynames the client requested, |
|
191 | + * encoded in clark-notation {xmlnamespace}tagname |
|
192 | + * |
|
193 | + * If the array is empty, it means 'all properties' were requested. |
|
194 | + * |
|
195 | + * @param array $properties |
|
196 | + * |
|
197 | + * @return array |
|
198 | + */ |
|
199 | + public function getProperties($properties) |
|
200 | + { |
|
201 | + $response = []; |
|
202 | + foreach ($properties as $propertyName) { |
|
203 | + if (isset($this->addressBookInfo[$propertyName])) { |
|
204 | + $response[$propertyName] = $this->addressBookInfo[$propertyName]; |
|
205 | + } |
|
206 | + } |
|
207 | 207 | |
208 | - return $response; |
|
209 | - } |
|
208 | + return $response; |
|
209 | + } |
|
210 | 210 | |
211 | - /** |
|
212 | - * Returns the owner principal. |
|
213 | - * |
|
214 | - * This must be a url to a principal, or null if there's no owner |
|
215 | - * |
|
216 | - * @return string|null |
|
217 | - */ |
|
218 | - public function getOwner() |
|
219 | - { |
|
220 | - return $this->addressBookInfo['principaluri']; |
|
221 | - } |
|
211 | + /** |
|
212 | + * Returns the owner principal. |
|
213 | + * |
|
214 | + * This must be a url to a principal, or null if there's no owner |
|
215 | + * |
|
216 | + * @return string|null |
|
217 | + */ |
|
218 | + public function getOwner() |
|
219 | + { |
|
220 | + return $this->addressBookInfo['principaluri']; |
|
221 | + } |
|
222 | 222 | |
223 | - /** |
|
224 | - * This method returns the ACL's for card nodes in this address book. |
|
225 | - * The result of this method automatically gets passed to the |
|
226 | - * card nodes in this address book. |
|
227 | - * |
|
228 | - * @return array |
|
229 | - */ |
|
230 | - public function getChildACL() |
|
231 | - { |
|
232 | - return [ |
|
233 | - [ |
|
234 | - 'privilege' => '{DAV:}all', |
|
235 | - 'principal' => $this->getOwner(), |
|
236 | - 'protected' => true, |
|
237 | - ], |
|
238 | - ]; |
|
239 | - } |
|
223 | + /** |
|
224 | + * This method returns the ACL's for card nodes in this address book. |
|
225 | + * The result of this method automatically gets passed to the |
|
226 | + * card nodes in this address book. |
|
227 | + * |
|
228 | + * @return array |
|
229 | + */ |
|
230 | + public function getChildACL() |
|
231 | + { |
|
232 | + return [ |
|
233 | + [ |
|
234 | + 'privilege' => '{DAV:}all', |
|
235 | + 'principal' => $this->getOwner(), |
|
236 | + 'protected' => true, |
|
237 | + ], |
|
238 | + ]; |
|
239 | + } |
|
240 | 240 | |
241 | - /** |
|
242 | - * This method returns the current sync-token for this collection. |
|
243 | - * This can be any string. |
|
244 | - * |
|
245 | - * If null is returned from this function, the plugin assumes there's no |
|
246 | - * sync information available. |
|
247 | - * |
|
248 | - * @return string|null |
|
249 | - */ |
|
250 | - public function getSyncToken() |
|
251 | - { |
|
252 | - if ( |
|
253 | - $this->carddavBackend instanceof Backend\SyncSupport && |
|
254 | - isset($this->addressBookInfo['{DAV:}sync-token']) |
|
255 | - ) { |
|
256 | - return $this->addressBookInfo['{DAV:}sync-token']; |
|
257 | - } |
|
258 | - if ( |
|
259 | - $this->carddavBackend instanceof Backend\SyncSupport && |
|
260 | - isset($this->addressBookInfo['{http://sabredav.org/ns}sync-token']) |
|
261 | - ) { |
|
262 | - return $this->addressBookInfo['{http://sabredav.org/ns}sync-token']; |
|
263 | - } |
|
264 | - } |
|
241 | + /** |
|
242 | + * This method returns the current sync-token for this collection. |
|
243 | + * This can be any string. |
|
244 | + * |
|
245 | + * If null is returned from this function, the plugin assumes there's no |
|
246 | + * sync information available. |
|
247 | + * |
|
248 | + * @return string|null |
|
249 | + */ |
|
250 | + public function getSyncToken() |
|
251 | + { |
|
252 | + if ( |
|
253 | + $this->carddavBackend instanceof Backend\SyncSupport && |
|
254 | + isset($this->addressBookInfo['{DAV:}sync-token']) |
|
255 | + ) { |
|
256 | + return $this->addressBookInfo['{DAV:}sync-token']; |
|
257 | + } |
|
258 | + if ( |
|
259 | + $this->carddavBackend instanceof Backend\SyncSupport && |
|
260 | + isset($this->addressBookInfo['{http://sabredav.org/ns}sync-token']) |
|
261 | + ) { |
|
262 | + return $this->addressBookInfo['{http://sabredav.org/ns}sync-token']; |
|
263 | + } |
|
264 | + } |
|
265 | 265 | |
266 | - /** |
|
267 | - * The getChanges method returns all the changes that have happened, since |
|
268 | - * the specified syncToken and the current collection. |
|
269 | - * |
|
270 | - * This function should return an array, such as the following: |
|
271 | - * |
|
272 | - * [ |
|
273 | - * 'syncToken' => 'The current synctoken', |
|
274 | - * 'added' => [ |
|
275 | - * 'new.txt', |
|
276 | - * ], |
|
277 | - * 'modified' => [ |
|
278 | - * 'modified.txt', |
|
279 | - * ], |
|
280 | - * 'deleted' => [ |
|
281 | - * 'foo.php.bak', |
|
282 | - * 'old.txt' |
|
283 | - * ] |
|
284 | - * ]; |
|
285 | - * |
|
286 | - * The syncToken property should reflect the *current* syncToken of the |
|
287 | - * collection, as reported getSyncToken(). This is needed here too, to |
|
288 | - * ensure the operation is atomic. |
|
289 | - * |
|
290 | - * If the syncToken is specified as null, this is an initial sync, and all |
|
291 | - * members should be reported. |
|
292 | - * |
|
293 | - * The modified property is an array of nodenames that have changed since |
|
294 | - * the last token. |
|
295 | - * |
|
296 | - * The deleted property is an array with nodenames, that have been deleted |
|
297 | - * from collection. |
|
298 | - * |
|
299 | - * The second argument is basically the 'depth' of the report. If it's 1, |
|
300 | - * you only have to report changes that happened only directly in immediate |
|
301 | - * descendants. If it's 2, it should also include changes from the nodes |
|
302 | - * below the child collections. (grandchildren) |
|
303 | - * |
|
304 | - * The third (optional) argument allows a client to specify how many |
|
305 | - * results should be returned at most. If the limit is not specified, it |
|
306 | - * should be treated as infinite. |
|
307 | - * |
|
308 | - * If the limit (infinite or not) is higher than you're willing to return, |
|
309 | - * you should throw a Sabre\DAV\Exception\TooMuchMatches() exception. |
|
310 | - * |
|
311 | - * If the syncToken is expired (due to data cleanup) or unknown, you must |
|
312 | - * return null. |
|
313 | - * |
|
314 | - * The limit is 'suggestive'. You are free to ignore it. |
|
315 | - * |
|
316 | - * @param string $syncToken |
|
317 | - * @param int $syncLevel |
|
318 | - * @param int $limit |
|
319 | - * |
|
320 | - * @return array |
|
321 | - */ |
|
322 | - public function getChanges($syncToken, $syncLevel, $limit = null) |
|
323 | - { |
|
324 | - if (!$this->carddavBackend instanceof Backend\SyncSupport) { |
|
325 | - return null; |
|
326 | - } |
|
266 | + /** |
|
267 | + * The getChanges method returns all the changes that have happened, since |
|
268 | + * the specified syncToken and the current collection. |
|
269 | + * |
|
270 | + * This function should return an array, such as the following: |
|
271 | + * |
|
272 | + * [ |
|
273 | + * 'syncToken' => 'The current synctoken', |
|
274 | + * 'added' => [ |
|
275 | + * 'new.txt', |
|
276 | + * ], |
|
277 | + * 'modified' => [ |
|
278 | + * 'modified.txt', |
|
279 | + * ], |
|
280 | + * 'deleted' => [ |
|
281 | + * 'foo.php.bak', |
|
282 | + * 'old.txt' |
|
283 | + * ] |
|
284 | + * ]; |
|
285 | + * |
|
286 | + * The syncToken property should reflect the *current* syncToken of the |
|
287 | + * collection, as reported getSyncToken(). This is needed here too, to |
|
288 | + * ensure the operation is atomic. |
|
289 | + * |
|
290 | + * If the syncToken is specified as null, this is an initial sync, and all |
|
291 | + * members should be reported. |
|
292 | + * |
|
293 | + * The modified property is an array of nodenames that have changed since |
|
294 | + * the last token. |
|
295 | + * |
|
296 | + * The deleted property is an array with nodenames, that have been deleted |
|
297 | + * from collection. |
|
298 | + * |
|
299 | + * The second argument is basically the 'depth' of the report. If it's 1, |
|
300 | + * you only have to report changes that happened only directly in immediate |
|
301 | + * descendants. If it's 2, it should also include changes from the nodes |
|
302 | + * below the child collections. (grandchildren) |
|
303 | + * |
|
304 | + * The third (optional) argument allows a client to specify how many |
|
305 | + * results should be returned at most. If the limit is not specified, it |
|
306 | + * should be treated as infinite. |
|
307 | + * |
|
308 | + * If the limit (infinite or not) is higher than you're willing to return, |
|
309 | + * you should throw a Sabre\DAV\Exception\TooMuchMatches() exception. |
|
310 | + * |
|
311 | + * If the syncToken is expired (due to data cleanup) or unknown, you must |
|
312 | + * return null. |
|
313 | + * |
|
314 | + * The limit is 'suggestive'. You are free to ignore it. |
|
315 | + * |
|
316 | + * @param string $syncToken |
|
317 | + * @param int $syncLevel |
|
318 | + * @param int $limit |
|
319 | + * |
|
320 | + * @return array |
|
321 | + */ |
|
322 | + public function getChanges($syncToken, $syncLevel, $limit = null) |
|
323 | + { |
|
324 | + if (!$this->carddavBackend instanceof Backend\SyncSupport) { |
|
325 | + return null; |
|
326 | + } |
|
327 | 327 | |
328 | - return $this->carddavBackend->getChangesForAddressBook( |
|
329 | - $this->addressBookInfo['id'], |
|
330 | - $syncToken, |
|
331 | - $syncLevel, |
|
332 | - $limit |
|
333 | - ); |
|
334 | - } |
|
328 | + return $this->carddavBackend->getChangesForAddressBook( |
|
329 | + $this->addressBookInfo['id'], |
|
330 | + $syncToken, |
|
331 | + $syncLevel, |
|
332 | + $limit |
|
333 | + ); |
|
334 | + } |
|
335 | 335 | } |