@@ -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 | } |
@@ -61,22 +61,22 @@ |
||
| 61 | 61 | if (is_array($elems)) { |
| 62 | 62 | foreach ($elems as $elem) { |
| 63 | 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'; |
|
| 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; |
|
| 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 | 80 | } |
| 81 | 81 | } |
| 82 | 82 | } |
@@ -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 | } |
@@ -67,25 +67,25 @@ |
||
| 67 | 67 | if (is_array($elems)) { |
| 68 | 68 | foreach ($elems as $elem) { |
| 69 | 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'; |
|
| 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; |
|
| 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 | 89 | } |
| 90 | 90 | } |
| 91 | 91 | } |
@@ -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 | } |
@@ -53,11 +53,11 @@ |
||
| 53 | 53 | ]; |
| 54 | 54 | |
| 55 | 55 | $elems = (array) $reader->parseInnerTree(); |
| 56 | - $elems = array_filter($elems, function ($element) { |
|
| 56 | + $elems = array_filter($elems, function($element) { |
|
| 57 | 57 | return '{urn:ietf:params:xml:ns:carddav}prop' === $element['name'] && |
| 58 | 58 | isset($element['attributes']['name']); |
| 59 | 59 | }); |
| 60 | - $result['addressDataProperties'] = array_map(function ($element) { |
|
| 60 | + $result['addressDataProperties'] = array_map(function($element) { |
|
| 61 | 61 | return $element['attributes']['name']; |
| 62 | 62 | }, $elems); |
| 63 | 63 | |
@@ -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 | } |
@@ -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 | } |
@@ -17,56 +17,56 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | interface IACL extends DAV\INode |
| 19 | 19 | { |
| 20 | - /** |
|
| 21 | - * Returns the owner principal. |
|
| 22 | - * |
|
| 23 | - * This must be a url to a principal, or null if there's no owner |
|
| 24 | - * |
|
| 25 | - * @return string|null |
|
| 26 | - */ |
|
| 27 | - public function getOwner(); |
|
| 20 | + /** |
|
| 21 | + * Returns the owner principal. |
|
| 22 | + * |
|
| 23 | + * This must be a url to a principal, or null if there's no owner |
|
| 24 | + * |
|
| 25 | + * @return string|null |
|
| 26 | + */ |
|
| 27 | + public function getOwner(); |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Returns a group principal. |
|
| 31 | - * |
|
| 32 | - * This must be a url to a principal, or null if there's no owner |
|
| 33 | - * |
|
| 34 | - * @return string|null |
|
| 35 | - */ |
|
| 36 | - public function getGroup(); |
|
| 29 | + /** |
|
| 30 | + * Returns a group principal. |
|
| 31 | + * |
|
| 32 | + * This must be a url to a principal, or null if there's no owner |
|
| 33 | + * |
|
| 34 | + * @return string|null |
|
| 35 | + */ |
|
| 36 | + public function getGroup(); |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Returns a list of ACE's for this node. |
|
| 40 | - * |
|
| 41 | - * Each ACE has the following properties: |
|
| 42 | - * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are |
|
| 43 | - * currently the only supported privileges |
|
| 44 | - * * 'principal', a url to the principal who owns the node |
|
| 45 | - * * 'protected' (optional), indicating that this ACE is not allowed to |
|
| 46 | - * be updated. |
|
| 47 | - * |
|
| 48 | - * @return array |
|
| 49 | - */ |
|
| 50 | - public function getACL(); |
|
| 38 | + /** |
|
| 39 | + * Returns a list of ACE's for this node. |
|
| 40 | + * |
|
| 41 | + * Each ACE has the following properties: |
|
| 42 | + * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are |
|
| 43 | + * currently the only supported privileges |
|
| 44 | + * * 'principal', a url to the principal who owns the node |
|
| 45 | + * * 'protected' (optional), indicating that this ACE is not allowed to |
|
| 46 | + * be updated. |
|
| 47 | + * |
|
| 48 | + * @return array |
|
| 49 | + */ |
|
| 50 | + public function getACL(); |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * Updates the ACL. |
|
| 54 | - * |
|
| 55 | - * This method will receive a list of new ACE's as an array argument. |
|
| 56 | - */ |
|
| 57 | - public function setACL(array $acl); |
|
| 52 | + /** |
|
| 53 | + * Updates the ACL. |
|
| 54 | + * |
|
| 55 | + * This method will receive a list of new ACE's as an array argument. |
|
| 56 | + */ |
|
| 57 | + public function setACL(array $acl); |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Returns the list of supported privileges for this node. |
|
| 61 | - * |
|
| 62 | - * The returned data structure is a list of nested privileges. |
|
| 63 | - * See Sabre\DAVACL\Plugin::getDefaultSupportedPrivilegeSet for a simple |
|
| 64 | - * standard structure. |
|
| 65 | - * |
|
| 66 | - * If null is returned from this method, the default privilege set is used, |
|
| 67 | - * which is fine for most common usecases. |
|
| 68 | - * |
|
| 69 | - * @return array|null |
|
| 70 | - */ |
|
| 71 | - public function getSupportedPrivilegeSet(); |
|
| 59 | + /** |
|
| 60 | + * Returns the list of supported privileges for this node. |
|
| 61 | + * |
|
| 62 | + * The returned data structure is a list of nested privileges. |
|
| 63 | + * See Sabre\DAVACL\Plugin::getDefaultSupportedPrivilegeSet for a simple |
|
| 64 | + * standard structure. |
|
| 65 | + * |
|
| 66 | + * If null is returned from this method, the default privilege set is used, |
|
| 67 | + * which is fine for most common usecases. |
|
| 68 | + * |
|
| 69 | + * @return array|null |
|
| 70 | + */ |
|
| 71 | + public function getSupportedPrivilegeSet(); |
|
| 72 | 72 | } |
@@ -24,176 +24,176 @@ |
||
| 24 | 24 | */ |
| 25 | 25 | class Principal extends DAV\Node implements IPrincipal, DAV\IProperties, IACL |
| 26 | 26 | { |
| 27 | - use ACLTrait; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Struct with principal information. |
|
| 31 | - * |
|
| 32 | - * @var array |
|
| 33 | - */ |
|
| 34 | - protected $principalProperties; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * Principal backend. |
|
| 38 | - * |
|
| 39 | - * @var PrincipalBackend\BackendInterface |
|
| 40 | - */ |
|
| 41 | - protected $principalBackend; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Creates the principal object. |
|
| 45 | - */ |
|
| 46 | - public function __construct(PrincipalBackend\BackendInterface $principalBackend, array $principalProperties = []) |
|
| 47 | - { |
|
| 48 | - if (!isset($principalProperties['uri'])) { |
|
| 49 | - throw new DAV\Exception('The principal properties must at least contain the \'uri\' key'); |
|
| 50 | - } |
|
| 51 | - $this->principalBackend = $principalBackend; |
|
| 52 | - $this->principalProperties = $principalProperties; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * Returns the full principal url. |
|
| 57 | - * |
|
| 58 | - * @return string |
|
| 59 | - */ |
|
| 60 | - public function getPrincipalUrl() |
|
| 61 | - { |
|
| 62 | - return $this->principalProperties['uri']; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Returns a list of alternative urls for a principal. |
|
| 67 | - * |
|
| 68 | - * This can for example be an email address, or ldap url. |
|
| 69 | - * |
|
| 70 | - * @return array |
|
| 71 | - */ |
|
| 72 | - public function getAlternateUriSet() |
|
| 73 | - { |
|
| 74 | - $uris = []; |
|
| 75 | - if (isset($this->principalProperties['{DAV:}alternate-URI-set'])) { |
|
| 76 | - $uris = $this->principalProperties['{DAV:}alternate-URI-set']; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - if (isset($this->principalProperties['{http://sabredav.org/ns}email-address'])) { |
|
| 80 | - $uris[] = 'mailto:'.$this->principalProperties['{http://sabredav.org/ns}email-address']; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - return array_unique($uris); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Returns the list of group members. |
|
| 88 | - * |
|
| 89 | - * If this principal is a group, this function should return |
|
| 90 | - * all member principal uri's for the group. |
|
| 91 | - * |
|
| 92 | - * @return array |
|
| 93 | - */ |
|
| 94 | - public function getGroupMemberSet() |
|
| 95 | - { |
|
| 96 | - return $this->principalBackend->getGroupMemberSet($this->principalProperties['uri']); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * Returns the list of groups this principal is member of. |
|
| 101 | - * |
|
| 102 | - * If this principal is a member of a (list of) groups, this function |
|
| 103 | - * should return a list of principal uri's for it's members. |
|
| 104 | - * |
|
| 105 | - * @return array |
|
| 106 | - */ |
|
| 107 | - public function getGroupMembership() |
|
| 108 | - { |
|
| 109 | - return $this->principalBackend->getGroupMemberShip($this->principalProperties['uri']); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Sets a list of group members. |
|
| 114 | - * |
|
| 115 | - * If this principal is a group, this method sets all the group members. |
|
| 116 | - * The list of members is always overwritten, never appended to. |
|
| 117 | - * |
|
| 118 | - * This method should throw an exception if the members could not be set. |
|
| 119 | - */ |
|
| 120 | - public function setGroupMemberSet(array $groupMembers) |
|
| 121 | - { |
|
| 122 | - $this->principalBackend->setGroupMemberSet($this->principalProperties['uri'], $groupMembers); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * Returns this principals name. |
|
| 127 | - * |
|
| 128 | - * @return string |
|
| 129 | - */ |
|
| 130 | - public function getName() |
|
| 131 | - { |
|
| 132 | - $uri = $this->principalProperties['uri']; |
|
| 133 | - list(, $name) = Uri\split($uri); |
|
| 134 | - |
|
| 135 | - return $name; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * Returns the name of the user. |
|
| 140 | - * |
|
| 141 | - * @return string |
|
| 142 | - */ |
|
| 143 | - public function getDisplayName() |
|
| 144 | - { |
|
| 145 | - if (isset($this->principalProperties['{DAV:}displayname'])) { |
|
| 146 | - return $this->principalProperties['{DAV:}displayname']; |
|
| 147 | - } else { |
|
| 148 | - return $this->getName(); |
|
| 149 | - } |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * Returns a list of properties. |
|
| 154 | - * |
|
| 155 | - * @param array $requestedProperties |
|
| 156 | - * |
|
| 157 | - * @return array |
|
| 158 | - */ |
|
| 159 | - public function getProperties($requestedProperties) |
|
| 160 | - { |
|
| 161 | - $newProperties = []; |
|
| 162 | - foreach ($requestedProperties as $propName) { |
|
| 163 | - if (isset($this->principalProperties[$propName])) { |
|
| 164 | - $newProperties[$propName] = $this->principalProperties[$propName]; |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - return $newProperties; |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * Updates properties on this node. |
|
| 173 | - * |
|
| 174 | - * This method received a PropPatch object, which contains all the |
|
| 175 | - * information about the update. |
|
| 176 | - * |
|
| 177 | - * To update specific properties, call the 'handle' method on this object. |
|
| 178 | - * Read the PropPatch documentation for more information. |
|
| 179 | - */ |
|
| 180 | - public function propPatch(DAV\PropPatch $propPatch) |
|
| 181 | - { |
|
| 182 | - return $this->principalBackend->updatePrincipal( |
|
| 183 | - $this->principalProperties['uri'], |
|
| 184 | - $propPatch |
|
| 185 | - ); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * Returns the owner principal. |
|
| 190 | - * |
|
| 191 | - * This must be a url to a principal, or null if there's no owner |
|
| 192 | - * |
|
| 193 | - * @return string|null |
|
| 194 | - */ |
|
| 195 | - public function getOwner() |
|
| 196 | - { |
|
| 197 | - return $this->principalProperties['uri']; |
|
| 198 | - } |
|
| 27 | + use ACLTrait; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Struct with principal information. |
|
| 31 | + * |
|
| 32 | + * @var array |
|
| 33 | + */ |
|
| 34 | + protected $principalProperties; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * Principal backend. |
|
| 38 | + * |
|
| 39 | + * @var PrincipalBackend\BackendInterface |
|
| 40 | + */ |
|
| 41 | + protected $principalBackend; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Creates the principal object. |
|
| 45 | + */ |
|
| 46 | + public function __construct(PrincipalBackend\BackendInterface $principalBackend, array $principalProperties = []) |
|
| 47 | + { |
|
| 48 | + if (!isset($principalProperties['uri'])) { |
|
| 49 | + throw new DAV\Exception('The principal properties must at least contain the \'uri\' key'); |
|
| 50 | + } |
|
| 51 | + $this->principalBackend = $principalBackend; |
|
| 52 | + $this->principalProperties = $principalProperties; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * Returns the full principal url. |
|
| 57 | + * |
|
| 58 | + * @return string |
|
| 59 | + */ |
|
| 60 | + public function getPrincipalUrl() |
|
| 61 | + { |
|
| 62 | + return $this->principalProperties['uri']; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Returns a list of alternative urls for a principal. |
|
| 67 | + * |
|
| 68 | + * This can for example be an email address, or ldap url. |
|
| 69 | + * |
|
| 70 | + * @return array |
|
| 71 | + */ |
|
| 72 | + public function getAlternateUriSet() |
|
| 73 | + { |
|
| 74 | + $uris = []; |
|
| 75 | + if (isset($this->principalProperties['{DAV:}alternate-URI-set'])) { |
|
| 76 | + $uris = $this->principalProperties['{DAV:}alternate-URI-set']; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + if (isset($this->principalProperties['{http://sabredav.org/ns}email-address'])) { |
|
| 80 | + $uris[] = 'mailto:'.$this->principalProperties['{http://sabredav.org/ns}email-address']; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + return array_unique($uris); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Returns the list of group members. |
|
| 88 | + * |
|
| 89 | + * If this principal is a group, this function should return |
|
| 90 | + * all member principal uri's for the group. |
|
| 91 | + * |
|
| 92 | + * @return array |
|
| 93 | + */ |
|
| 94 | + public function getGroupMemberSet() |
|
| 95 | + { |
|
| 96 | + return $this->principalBackend->getGroupMemberSet($this->principalProperties['uri']); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * Returns the list of groups this principal is member of. |
|
| 101 | + * |
|
| 102 | + * If this principal is a member of a (list of) groups, this function |
|
| 103 | + * should return a list of principal uri's for it's members. |
|
| 104 | + * |
|
| 105 | + * @return array |
|
| 106 | + */ |
|
| 107 | + public function getGroupMembership() |
|
| 108 | + { |
|
| 109 | + return $this->principalBackend->getGroupMemberShip($this->principalProperties['uri']); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * Sets a list of group members. |
|
| 114 | + * |
|
| 115 | + * If this principal is a group, this method sets all the group members. |
|
| 116 | + * The list of members is always overwritten, never appended to. |
|
| 117 | + * |
|
| 118 | + * This method should throw an exception if the members could not be set. |
|
| 119 | + */ |
|
| 120 | + public function setGroupMemberSet(array $groupMembers) |
|
| 121 | + { |
|
| 122 | + $this->principalBackend->setGroupMemberSet($this->principalProperties['uri'], $groupMembers); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * Returns this principals name. |
|
| 127 | + * |
|
| 128 | + * @return string |
|
| 129 | + */ |
|
| 130 | + public function getName() |
|
| 131 | + { |
|
| 132 | + $uri = $this->principalProperties['uri']; |
|
| 133 | + list(, $name) = Uri\split($uri); |
|
| 134 | + |
|
| 135 | + return $name; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * Returns the name of the user. |
|
| 140 | + * |
|
| 141 | + * @return string |
|
| 142 | + */ |
|
| 143 | + public function getDisplayName() |
|
| 144 | + { |
|
| 145 | + if (isset($this->principalProperties['{DAV:}displayname'])) { |
|
| 146 | + return $this->principalProperties['{DAV:}displayname']; |
|
| 147 | + } else { |
|
| 148 | + return $this->getName(); |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * Returns a list of properties. |
|
| 154 | + * |
|
| 155 | + * @param array $requestedProperties |
|
| 156 | + * |
|
| 157 | + * @return array |
|
| 158 | + */ |
|
| 159 | + public function getProperties($requestedProperties) |
|
| 160 | + { |
|
| 161 | + $newProperties = []; |
|
| 162 | + foreach ($requestedProperties as $propName) { |
|
| 163 | + if (isset($this->principalProperties[$propName])) { |
|
| 164 | + $newProperties[$propName] = $this->principalProperties[$propName]; |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + return $newProperties; |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * Updates properties on this node. |
|
| 173 | + * |
|
| 174 | + * This method received a PropPatch object, which contains all the |
|
| 175 | + * information about the update. |
|
| 176 | + * |
|
| 177 | + * To update specific properties, call the 'handle' method on this object. |
|
| 178 | + * Read the PropPatch documentation for more information. |
|
| 179 | + */ |
|
| 180 | + public function propPatch(DAV\PropPatch $propPatch) |
|
| 181 | + { |
|
| 182 | + return $this->principalBackend->updatePrincipal( |
|
| 183 | + $this->principalProperties['uri'], |
|
| 184 | + $propPatch |
|
| 185 | + ); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * Returns the owner principal. |
|
| 190 | + * |
|
| 191 | + * This must be a url to a principal, or null if there's no owner |
|
| 192 | + * |
|
| 193 | + * @return string|null |
|
| 194 | + */ |
|
| 195 | + public function getOwner() |
|
| 196 | + { |
|
| 197 | + return $this->principalProperties['uri']; |
|
| 198 | + } |
|
| 199 | 199 | } |
@@ -17,59 +17,59 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | interface IPrincipal extends DAV\INode |
| 19 | 19 | { |
| 20 | - /** |
|
| 21 | - * Returns a list of alternative urls for a principal. |
|
| 22 | - * |
|
| 23 | - * This can for example be an email address, or ldap url. |
|
| 24 | - * |
|
| 25 | - * @return array |
|
| 26 | - */ |
|
| 27 | - public function getAlternateUriSet(); |
|
| 20 | + /** |
|
| 21 | + * Returns a list of alternative urls for a principal. |
|
| 22 | + * |
|
| 23 | + * This can for example be an email address, or ldap url. |
|
| 24 | + * |
|
| 25 | + * @return array |
|
| 26 | + */ |
|
| 27 | + public function getAlternateUriSet(); |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Returns the full principal url. |
|
| 31 | - * |
|
| 32 | - * @return string |
|
| 33 | - */ |
|
| 34 | - public function getPrincipalUrl(); |
|
| 29 | + /** |
|
| 30 | + * Returns the full principal url. |
|
| 31 | + * |
|
| 32 | + * @return string |
|
| 33 | + */ |
|
| 34 | + public function getPrincipalUrl(); |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Returns the list of group members. |
|
| 38 | - * |
|
| 39 | - * If this principal is a group, this function should return |
|
| 40 | - * all member principal uri's for the group. |
|
| 41 | - * |
|
| 42 | - * @return array |
|
| 43 | - */ |
|
| 44 | - public function getGroupMemberSet(); |
|
| 36 | + /** |
|
| 37 | + * Returns the list of group members. |
|
| 38 | + * |
|
| 39 | + * If this principal is a group, this function should return |
|
| 40 | + * all member principal uri's for the group. |
|
| 41 | + * |
|
| 42 | + * @return array |
|
| 43 | + */ |
|
| 44 | + public function getGroupMemberSet(); |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Returns the list of groups this principal is member of. |
|
| 48 | - * |
|
| 49 | - * If this principal is a member of a (list of) groups, this function |
|
| 50 | - * should return a list of principal uri's for it's members. |
|
| 51 | - * |
|
| 52 | - * @return array |
|
| 53 | - */ |
|
| 54 | - public function getGroupMembership(); |
|
| 46 | + /** |
|
| 47 | + * Returns the list of groups this principal is member of. |
|
| 48 | + * |
|
| 49 | + * If this principal is a member of a (list of) groups, this function |
|
| 50 | + * should return a list of principal uri's for it's members. |
|
| 51 | + * |
|
| 52 | + * @return array |
|
| 53 | + */ |
|
| 54 | + public function getGroupMembership(); |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * Sets a list of group members. |
|
| 58 | - * |
|
| 59 | - * If this principal is a group, this method sets all the group members. |
|
| 60 | - * The list of members is always overwritten, never appended to. |
|
| 61 | - * |
|
| 62 | - * This method should throw an exception if the members could not be set. |
|
| 63 | - */ |
|
| 64 | - public function setGroupMemberSet(array $principals); |
|
| 56 | + /** |
|
| 57 | + * Sets a list of group members. |
|
| 58 | + * |
|
| 59 | + * If this principal is a group, this method sets all the group members. |
|
| 60 | + * The list of members is always overwritten, never appended to. |
|
| 61 | + * |
|
| 62 | + * This method should throw an exception if the members could not be set. |
|
| 63 | + */ |
|
| 64 | + public function setGroupMemberSet(array $principals); |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * Returns the displayname. |
|
| 68 | - * |
|
| 69 | - * This should be a human readable name for the principal. |
|
| 70 | - * If none is available, return the nodename. |
|
| 71 | - * |
|
| 72 | - * @return string |
|
| 73 | - */ |
|
| 74 | - public function getDisplayName(); |
|
| 66 | + /** |
|
| 67 | + * Returns the displayname. |
|
| 68 | + * |
|
| 69 | + * This should be a human readable name for the principal. |
|
| 70 | + * If none is available, return the nodename. |
|
| 71 | + * |
|
| 72 | + * @return string |
|
| 73 | + */ |
|
| 74 | + public function getDisplayName(); |
|
| 75 | 75 | } |