@@ -20,103 +20,103 @@ |
||
| 20 | 20 | */ |
| 21 | 21 | class SyncCollectionReport implements XmlDeserializable { |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * The sync-token the client supplied for the report. |
|
| 25 | - * |
|
| 26 | - * @var string|null |
|
| 27 | - */ |
|
| 28 | - public $syncToken; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * The 'depth' of the sync the client is interested in. |
|
| 32 | - * |
|
| 33 | - * @var int |
|
| 34 | - */ |
|
| 35 | - public $syncLevel; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Maximum amount of items returned. |
|
| 39 | - * |
|
| 40 | - * @var int|null |
|
| 41 | - */ |
|
| 42 | - public $limit; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * The list of properties that are being requested for every change. |
|
| 46 | - * |
|
| 47 | - * @var null|array |
|
| 48 | - */ |
|
| 49 | - public $properties; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * The deserialize method is called during xml parsing. |
|
| 53 | - * |
|
| 54 | - * This method is called statictly, this is because in theory this method |
|
| 55 | - * may be used as a type of constructor, or factory method. |
|
| 56 | - * |
|
| 57 | - * Often you want to return an instance of the current class, but you are |
|
| 58 | - * free to return other data as well. |
|
| 59 | - * |
|
| 60 | - * You are responsible for advancing the reader to the next element. Not |
|
| 61 | - * doing anything will result in a never-ending loop. |
|
| 62 | - * |
|
| 63 | - * If you just want to skip parsing for this element altogether, you can |
|
| 64 | - * just call $reader->next(); |
|
| 65 | - * |
|
| 66 | - * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
| 67 | - * the next element. |
|
| 68 | - * |
|
| 69 | - * @param Reader $reader |
|
| 70 | - * @return mixed |
|
| 71 | - */ |
|
| 72 | - static function xmlDeserialize(Reader $reader) { |
|
| 73 | - |
|
| 74 | - $self = new self(); |
|
| 75 | - |
|
| 76 | - $reader->pushContext(); |
|
| 77 | - |
|
| 78 | - $reader->elementMap['{DAV:}prop'] = 'Sabre\Xml\Element\Elements'; |
|
| 79 | - $elems = KeyValue::xmlDeserialize($reader); |
|
| 80 | - |
|
| 81 | - $reader->popContext(); |
|
| 82 | - |
|
| 83 | - $required = [ |
|
| 84 | - '{DAV:}sync-token', |
|
| 85 | - '{DAV:}prop', |
|
| 86 | - ]; |
|
| 87 | - |
|
| 88 | - foreach ($required as $elem) { |
|
| 89 | - if (!array_key_exists($elem, $elems)) { |
|
| 90 | - throw new BadRequest('The ' . $elem . ' element in the {DAV:}sync-collection report is required'); |
|
| 91 | - } |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - |
|
| 95 | - $self->properties = $elems['{DAV:}prop']; |
|
| 96 | - $self->syncToken = $elems['{DAV:}sync-token']; |
|
| 97 | - |
|
| 98 | - if (isset($elems['{DAV:}limit'])) { |
|
| 99 | - $nresults = null; |
|
| 100 | - foreach ($elems['{DAV:}limit'] as $child) { |
|
| 101 | - if ($child['name'] === '{DAV:}nresults') { |
|
| 102 | - $nresults = (int)$child['value']; |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - $self->limit = $nresults; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - if (isset($elems['{DAV:}sync-level'])) { |
|
| 109 | - |
|
| 110 | - $value = $elems['{DAV:}sync-level']; |
|
| 111 | - if ($value === 'infinity') { |
|
| 112 | - $value = \Sabre\DAV\Server::DEPTH_INFINITY; |
|
| 113 | - } |
|
| 114 | - $self->syncLevel = $value; |
|
| 115 | - |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - return $self; |
|
| 119 | - |
|
| 120 | - } |
|
| 23 | + /** |
|
| 24 | + * The sync-token the client supplied for the report. |
|
| 25 | + * |
|
| 26 | + * @var string|null |
|
| 27 | + */ |
|
| 28 | + public $syncToken; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * The 'depth' of the sync the client is interested in. |
|
| 32 | + * |
|
| 33 | + * @var int |
|
| 34 | + */ |
|
| 35 | + public $syncLevel; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Maximum amount of items returned. |
|
| 39 | + * |
|
| 40 | + * @var int|null |
|
| 41 | + */ |
|
| 42 | + public $limit; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * The list of properties that are being requested for every change. |
|
| 46 | + * |
|
| 47 | + * @var null|array |
|
| 48 | + */ |
|
| 49 | + public $properties; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * The deserialize method is called during xml parsing. |
|
| 53 | + * |
|
| 54 | + * This method is called statictly, this is because in theory this method |
|
| 55 | + * may be used as a type of constructor, or factory method. |
|
| 56 | + * |
|
| 57 | + * Often you want to return an instance of the current class, but you are |
|
| 58 | + * free to return other data as well. |
|
| 59 | + * |
|
| 60 | + * You are responsible for advancing the reader to the next element. Not |
|
| 61 | + * doing anything will result in a never-ending loop. |
|
| 62 | + * |
|
| 63 | + * If you just want to skip parsing for this element altogether, you can |
|
| 64 | + * just call $reader->next(); |
|
| 65 | + * |
|
| 66 | + * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
| 67 | + * the next element. |
|
| 68 | + * |
|
| 69 | + * @param Reader $reader |
|
| 70 | + * @return mixed |
|
| 71 | + */ |
|
| 72 | + static function xmlDeserialize(Reader $reader) { |
|
| 73 | + |
|
| 74 | + $self = new self(); |
|
| 75 | + |
|
| 76 | + $reader->pushContext(); |
|
| 77 | + |
|
| 78 | + $reader->elementMap['{DAV:}prop'] = 'Sabre\Xml\Element\Elements'; |
|
| 79 | + $elems = KeyValue::xmlDeserialize($reader); |
|
| 80 | + |
|
| 81 | + $reader->popContext(); |
|
| 82 | + |
|
| 83 | + $required = [ |
|
| 84 | + '{DAV:}sync-token', |
|
| 85 | + '{DAV:}prop', |
|
| 86 | + ]; |
|
| 87 | + |
|
| 88 | + foreach ($required as $elem) { |
|
| 89 | + if (!array_key_exists($elem, $elems)) { |
|
| 90 | + throw new BadRequest('The ' . $elem . ' element in the {DAV:}sync-collection report is required'); |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + |
|
| 95 | + $self->properties = $elems['{DAV:}prop']; |
|
| 96 | + $self->syncToken = $elems['{DAV:}sync-token']; |
|
| 97 | + |
|
| 98 | + if (isset($elems['{DAV:}limit'])) { |
|
| 99 | + $nresults = null; |
|
| 100 | + foreach ($elems['{DAV:}limit'] as $child) { |
|
| 101 | + if ($child['name'] === '{DAV:}nresults') { |
|
| 102 | + $nresults = (int)$child['value']; |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + $self->limit = $nresults; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + if (isset($elems['{DAV:}sync-level'])) { |
|
| 109 | + |
|
| 110 | + $value = $elems['{DAV:}sync-level']; |
|
| 111 | + if ($value === 'infinity') { |
|
| 112 | + $value = \Sabre\DAV\Server::DEPTH_INFINITY; |
|
| 113 | + } |
|
| 114 | + $self->syncLevel = $value; |
|
| 115 | + |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + return $self; |
|
| 119 | + |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | 122 | } |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | |
| 76 | 76 | $reader->pushContext(); |
| 77 | 77 | |
| 78 | - $reader->elementMap['{DAV:}prop'] = 'Sabre\Xml\Element\Elements'; |
|
| 78 | + $reader->elementMap['{DAV:}prop'] = 'Sabre\Xml\Element\Elements'; |
|
| 79 | 79 | $elems = KeyValue::xmlDeserialize($reader); |
| 80 | 80 | |
| 81 | 81 | $reader->popContext(); |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | $nresults = null; |
| 100 | 100 | foreach ($elems['{DAV:}limit'] as $child) { |
| 101 | 101 | if ($child['name'] === '{DAV:}nresults') { |
| 102 | - $nresults = (int)$child['value']; |
|
| 102 | + $nresults = (int) $child['value']; |
|
| 103 | 103 | } |
| 104 | 104 | } |
| 105 | 105 | $self->limit = $nresults; |
@@ -126,9 +126,11 @@ |
||
| 126 | 126 | $responses = []; |
| 127 | 127 | $syncToken = null; |
| 128 | 128 | |
| 129 | - if ($elements) foreach ($elements as $elem) { |
|
| 129 | + if ($elements) { |
|
| 130 | + foreach ($elements as $elem) { |
|
| 130 | 131 | if ($elem['name'] === '{DAV:}response') { |
| 131 | 132 | $responses[] = $elem['value']; |
| 133 | + } |
|
| 132 | 134 | } |
| 133 | 135 | if ($elem['name'] === '{DAV:}sync-token') { |
| 134 | 136 | $syncToken = $elem['value']; |
@@ -21,122 +21,122 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | class MultiStatus implements Element { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * The responses |
|
| 26 | - * |
|
| 27 | - * @var \Sabre\DAV\Xml\Element\Response[] |
|
| 28 | - */ |
|
| 29 | - protected $responses; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * A sync token (from RFC6578). |
|
| 33 | - * |
|
| 34 | - * @var string |
|
| 35 | - */ |
|
| 36 | - protected $syncToken; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Constructor |
|
| 40 | - * |
|
| 41 | - * @param \Sabre\DAV\Xml\Element\Response[] $responses |
|
| 42 | - * @param string $syncToken |
|
| 43 | - */ |
|
| 44 | - public function __construct(array $responses, $syncToken = null) { |
|
| 45 | - |
|
| 46 | - $this->responses = $responses; |
|
| 47 | - $this->syncToken = $syncToken; |
|
| 48 | - |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Returns the response list. |
|
| 53 | - * |
|
| 54 | - * @return \Sabre\DAV\Xml\Element\Response[] |
|
| 55 | - */ |
|
| 56 | - public function getResponses() { |
|
| 57 | - |
|
| 58 | - return $this->responses; |
|
| 59 | - |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * Returns the sync-token, if available. |
|
| 64 | - * |
|
| 65 | - * @return string|null |
|
| 66 | - */ |
|
| 67 | - public function getSyncToken() { |
|
| 68 | - |
|
| 69 | - return $this->syncToken; |
|
| 70 | - |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * The serialize method is called during xml writing. |
|
| 75 | - * |
|
| 76 | - * It should use the $writer argument to encode this object into XML. |
|
| 77 | - * |
|
| 78 | - * Important note: it is not needed to create the parent element. The |
|
| 79 | - * parent element is already created, and we only have to worry about |
|
| 80 | - * attributes, child elements and text (if any). |
|
| 81 | - * |
|
| 82 | - * Important note 2: If you are writing any new elements, you are also |
|
| 83 | - * responsible for closing them. |
|
| 84 | - * |
|
| 85 | - * @param Writer $writer |
|
| 86 | - * @return void |
|
| 87 | - */ |
|
| 88 | - public function xmlSerialize(Writer $writer) { |
|
| 89 | - |
|
| 90 | - foreach ($this->getResponses() as $response) { |
|
| 91 | - $writer->writeElement('{DAV:}response', $response); |
|
| 92 | - } |
|
| 93 | - if ($syncToken = $this->getSyncToken()) { |
|
| 94 | - $writer->writeElement('{DAV:}sync-token', $syncToken); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * The deserialize method is called during xml parsing. |
|
| 101 | - * |
|
| 102 | - * This method is called statictly, this is because in theory this method |
|
| 103 | - * may be used as a type of constructor, or factory method. |
|
| 104 | - * |
|
| 105 | - * Often you want to return an instance of the current class, but you are |
|
| 106 | - * free to return other data as well. |
|
| 107 | - * |
|
| 108 | - * You are responsible for advancing the reader to the next element. Not |
|
| 109 | - * doing anything will result in a never-ending loop. |
|
| 110 | - * |
|
| 111 | - * If you just want to skip parsing for this element altogether, you can |
|
| 112 | - * just call $reader->next(); |
|
| 113 | - * |
|
| 114 | - * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
| 115 | - * the next element. |
|
| 116 | - * |
|
| 117 | - * @param Reader $reader |
|
| 118 | - * @return mixed |
|
| 119 | - */ |
|
| 120 | - static function xmlDeserialize(Reader $reader) { |
|
| 121 | - |
|
| 122 | - $elementMap = $reader->elementMap; |
|
| 123 | - $elementMap['{DAV:}prop'] = 'Sabre\\DAV\\Xml\\Element\\Prop'; |
|
| 124 | - $elements = $reader->parseInnerTree($elementMap); |
|
| 125 | - |
|
| 126 | - $responses = []; |
|
| 127 | - $syncToken = null; |
|
| 128 | - |
|
| 129 | - if ($elements) foreach ($elements as $elem) { |
|
| 130 | - if ($elem['name'] === '{DAV:}response') { |
|
| 131 | - $responses[] = $elem['value']; |
|
| 132 | - } |
|
| 133 | - if ($elem['name'] === '{DAV:}sync-token') { |
|
| 134 | - $syncToken = $elem['value']; |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - return new self($responses, $syncToken); |
|
| 139 | - |
|
| 140 | - } |
|
| 24 | + /** |
|
| 25 | + * The responses |
|
| 26 | + * |
|
| 27 | + * @var \Sabre\DAV\Xml\Element\Response[] |
|
| 28 | + */ |
|
| 29 | + protected $responses; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * A sync token (from RFC6578). |
|
| 33 | + * |
|
| 34 | + * @var string |
|
| 35 | + */ |
|
| 36 | + protected $syncToken; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Constructor |
|
| 40 | + * |
|
| 41 | + * @param \Sabre\DAV\Xml\Element\Response[] $responses |
|
| 42 | + * @param string $syncToken |
|
| 43 | + */ |
|
| 44 | + public function __construct(array $responses, $syncToken = null) { |
|
| 45 | + |
|
| 46 | + $this->responses = $responses; |
|
| 47 | + $this->syncToken = $syncToken; |
|
| 48 | + |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Returns the response list. |
|
| 53 | + * |
|
| 54 | + * @return \Sabre\DAV\Xml\Element\Response[] |
|
| 55 | + */ |
|
| 56 | + public function getResponses() { |
|
| 57 | + |
|
| 58 | + return $this->responses; |
|
| 59 | + |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * Returns the sync-token, if available. |
|
| 64 | + * |
|
| 65 | + * @return string|null |
|
| 66 | + */ |
|
| 67 | + public function getSyncToken() { |
|
| 68 | + |
|
| 69 | + return $this->syncToken; |
|
| 70 | + |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * The serialize method is called during xml writing. |
|
| 75 | + * |
|
| 76 | + * It should use the $writer argument to encode this object into XML. |
|
| 77 | + * |
|
| 78 | + * Important note: it is not needed to create the parent element. The |
|
| 79 | + * parent element is already created, and we only have to worry about |
|
| 80 | + * attributes, child elements and text (if any). |
|
| 81 | + * |
|
| 82 | + * Important note 2: If you are writing any new elements, you are also |
|
| 83 | + * responsible for closing them. |
|
| 84 | + * |
|
| 85 | + * @param Writer $writer |
|
| 86 | + * @return void |
|
| 87 | + */ |
|
| 88 | + public function xmlSerialize(Writer $writer) { |
|
| 89 | + |
|
| 90 | + foreach ($this->getResponses() as $response) { |
|
| 91 | + $writer->writeElement('{DAV:}response', $response); |
|
| 92 | + } |
|
| 93 | + if ($syncToken = $this->getSyncToken()) { |
|
| 94 | + $writer->writeElement('{DAV:}sync-token', $syncToken); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * The deserialize method is called during xml parsing. |
|
| 101 | + * |
|
| 102 | + * This method is called statictly, this is because in theory this method |
|
| 103 | + * may be used as a type of constructor, or factory method. |
|
| 104 | + * |
|
| 105 | + * Often you want to return an instance of the current class, but you are |
|
| 106 | + * free to return other data as well. |
|
| 107 | + * |
|
| 108 | + * You are responsible for advancing the reader to the next element. Not |
|
| 109 | + * doing anything will result in a never-ending loop. |
|
| 110 | + * |
|
| 111 | + * If you just want to skip parsing for this element altogether, you can |
|
| 112 | + * just call $reader->next(); |
|
| 113 | + * |
|
| 114 | + * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
| 115 | + * the next element. |
|
| 116 | + * |
|
| 117 | + * @param Reader $reader |
|
| 118 | + * @return mixed |
|
| 119 | + */ |
|
| 120 | + static function xmlDeserialize(Reader $reader) { |
|
| 121 | + |
|
| 122 | + $elementMap = $reader->elementMap; |
|
| 123 | + $elementMap['{DAV:}prop'] = 'Sabre\\DAV\\Xml\\Element\\Prop'; |
|
| 124 | + $elements = $reader->parseInnerTree($elementMap); |
|
| 125 | + |
|
| 126 | + $responses = []; |
|
| 127 | + $syncToken = null; |
|
| 128 | + |
|
| 129 | + if ($elements) foreach ($elements as $elem) { |
|
| 130 | + if ($elem['name'] === '{DAV:}response') { |
|
| 131 | + $responses[] = $elem['value']; |
|
| 132 | + } |
|
| 133 | + if ($elem['name'] === '{DAV:}sync-token') { |
|
| 134 | + $syncToken = $elem['value']; |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + return new self($responses, $syncToken); |
|
| 139 | + |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | 142 | } |
@@ -160,7 +160,7 @@ |
||
| 160 | 160 | static function xmlDeserialize(Reader $reader) { |
| 161 | 161 | |
| 162 | 162 | $hrefs = []; |
| 163 | - foreach ((array)$reader->parseInnerTree() as $elem) { |
|
| 163 | + foreach ((array) $reader->parseInnerTree() as $elem) { |
|
| 164 | 164 | if ($elem['name'] !== '{DAV:}href') |
| 165 | 165 | continue; |
| 166 | 166 | |
@@ -161,8 +161,9 @@ |
||
| 161 | 161 | |
| 162 | 162 | $hrefs = []; |
| 163 | 163 | foreach ((array)$reader->parseInnerTree() as $elem) { |
| 164 | - if ($elem['name'] !== '{DAV:}href') |
|
| 165 | - continue; |
|
| 164 | + if ($elem['name'] !== '{DAV:}href') { |
|
| 165 | + continue; |
|
| 166 | + } |
|
| 166 | 167 | |
| 167 | 168 | $hrefs[] = $elem['value']; |
| 168 | 169 | |
@@ -24,153 +24,153 @@ |
||
| 24 | 24 | */ |
| 25 | 25 | class Href implements Element, HtmlOutput { |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * List of uris |
|
| 29 | - * |
|
| 30 | - * @var array |
|
| 31 | - */ |
|
| 32 | - protected $hrefs; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * Automatically prefix the url with the server base directory |
|
| 36 | - * |
|
| 37 | - * @var bool |
|
| 38 | - */ |
|
| 39 | - protected $autoPrefix = true; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * Constructor |
|
| 43 | - * |
|
| 44 | - * You must either pass a string for a single href, or an array of hrefs. |
|
| 45 | - * |
|
| 46 | - * If auto-prefix is set to false, the hrefs will be treated as absolute |
|
| 47 | - * and not relative to the servers base uri. |
|
| 48 | - * |
|
| 49 | - * @param string|string[] $href |
|
| 50 | - * @param bool $autoPrefix |
|
| 51 | - */ |
|
| 52 | - public function __construct($hrefs, $autoPrefix = true) { |
|
| 53 | - |
|
| 54 | - if (is_string($hrefs)) { |
|
| 55 | - $hrefs = [$hrefs]; |
|
| 56 | - } |
|
| 57 | - $this->hrefs = $hrefs; |
|
| 58 | - $this->autoPrefix = $autoPrefix; |
|
| 59 | - |
|
| 60 | - |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Returns the first Href. |
|
| 65 | - * |
|
| 66 | - * @return string |
|
| 67 | - */ |
|
| 68 | - public function getHref() { |
|
| 69 | - |
|
| 70 | - return $this->hrefs[0]; |
|
| 71 | - |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * Returns the hrefs as an array |
|
| 76 | - * |
|
| 77 | - * @return array |
|
| 78 | - */ |
|
| 79 | - public function getHrefs() { |
|
| 80 | - |
|
| 81 | - return $this->hrefs; |
|
| 82 | - |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * The xmlSerialize metod is called during xml writing. |
|
| 87 | - * |
|
| 88 | - * Use the $writer argument to write its own xml serialization. |
|
| 89 | - * |
|
| 90 | - * An important note: do _not_ create a parent element. Any element |
|
| 91 | - * implementing XmlSerializble should only ever write what's considered |
|
| 92 | - * its 'inner xml'. |
|
| 93 | - * |
|
| 94 | - * The parent of the current element is responsible for writing a |
|
| 95 | - * containing element. |
|
| 96 | - * |
|
| 97 | - * This allows serializers to be re-used for different element names. |
|
| 98 | - * |
|
| 99 | - * If you are opening new elements, you must also close them again. |
|
| 100 | - * |
|
| 101 | - * @param Writer $writer |
|
| 102 | - * @return void |
|
| 103 | - */ |
|
| 104 | - public function xmlSerialize(Writer $writer) { |
|
| 105 | - |
|
| 106 | - foreach ($this->getHrefs() as $href) { |
|
| 107 | - if ($this->autoPrefix) { |
|
| 108 | - $href = $writer->contextUri . \Sabre\HTTP\encodePath($href); |
|
| 109 | - } |
|
| 110 | - $writer->writeElement('{DAV:}href', $href); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * Generate html representation for this value. |
|
| 117 | - * |
|
| 118 | - * The html output is 100% trusted, and no effort is being made to sanitize |
|
| 119 | - * it. It's up to the implementor to sanitize user provided values. |
|
| 120 | - * |
|
| 121 | - * The output must be in UTF-8. |
|
| 122 | - * |
|
| 123 | - * The baseUri parameter is a url to the root of the application, and can |
|
| 124 | - * be used to construct local links. |
|
| 125 | - * |
|
| 126 | - * @param HtmlOutputHelper $html |
|
| 127 | - * @return string |
|
| 128 | - */ |
|
| 129 | - public function toHtml(HtmlOutputHelper $html) { |
|
| 130 | - |
|
| 131 | - $links = []; |
|
| 132 | - foreach ($this->getHrefs() as $href) { |
|
| 133 | - $links[] = $html->link($href); |
|
| 134 | - } |
|
| 135 | - return implode('<br />', $links); |
|
| 136 | - |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * The deserialize method is called during xml parsing. |
|
| 141 | - * |
|
| 142 | - * This method is called statictly, this is because in theory this method |
|
| 143 | - * may be used as a type of constructor, or factory method. |
|
| 144 | - * |
|
| 145 | - * Often you want to return an instance of the current class, but you are |
|
| 146 | - * free to return other data as well. |
|
| 147 | - * |
|
| 148 | - * You are responsible for advancing the reader to the next element. Not |
|
| 149 | - * doing anything will result in a never-ending loop. |
|
| 150 | - * |
|
| 151 | - * If you just want to skip parsing for this element altogether, you can |
|
| 152 | - * just call $reader->next(); |
|
| 153 | - * |
|
| 154 | - * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
| 155 | - * the next element. |
|
| 156 | - * |
|
| 157 | - * @param Reader $reader |
|
| 158 | - * @return mixed |
|
| 159 | - */ |
|
| 160 | - static function xmlDeserialize(Reader $reader) { |
|
| 161 | - |
|
| 162 | - $hrefs = []; |
|
| 163 | - foreach ((array)$reader->parseInnerTree() as $elem) { |
|
| 164 | - if ($elem['name'] !== '{DAV:}href') |
|
| 165 | - continue; |
|
| 166 | - |
|
| 167 | - $hrefs[] = $elem['value']; |
|
| 168 | - |
|
| 169 | - } |
|
| 170 | - if ($hrefs) { |
|
| 171 | - return new self($hrefs, false); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - } |
|
| 27 | + /** |
|
| 28 | + * List of uris |
|
| 29 | + * |
|
| 30 | + * @var array |
|
| 31 | + */ |
|
| 32 | + protected $hrefs; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * Automatically prefix the url with the server base directory |
|
| 36 | + * |
|
| 37 | + * @var bool |
|
| 38 | + */ |
|
| 39 | + protected $autoPrefix = true; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * Constructor |
|
| 43 | + * |
|
| 44 | + * You must either pass a string for a single href, or an array of hrefs. |
|
| 45 | + * |
|
| 46 | + * If auto-prefix is set to false, the hrefs will be treated as absolute |
|
| 47 | + * and not relative to the servers base uri. |
|
| 48 | + * |
|
| 49 | + * @param string|string[] $href |
|
| 50 | + * @param bool $autoPrefix |
|
| 51 | + */ |
|
| 52 | + public function __construct($hrefs, $autoPrefix = true) { |
|
| 53 | + |
|
| 54 | + if (is_string($hrefs)) { |
|
| 55 | + $hrefs = [$hrefs]; |
|
| 56 | + } |
|
| 57 | + $this->hrefs = $hrefs; |
|
| 58 | + $this->autoPrefix = $autoPrefix; |
|
| 59 | + |
|
| 60 | + |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Returns the first Href. |
|
| 65 | + * |
|
| 66 | + * @return string |
|
| 67 | + */ |
|
| 68 | + public function getHref() { |
|
| 69 | + |
|
| 70 | + return $this->hrefs[0]; |
|
| 71 | + |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * Returns the hrefs as an array |
|
| 76 | + * |
|
| 77 | + * @return array |
|
| 78 | + */ |
|
| 79 | + public function getHrefs() { |
|
| 80 | + |
|
| 81 | + return $this->hrefs; |
|
| 82 | + |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * The xmlSerialize metod is called during xml writing. |
|
| 87 | + * |
|
| 88 | + * Use the $writer argument to write its own xml serialization. |
|
| 89 | + * |
|
| 90 | + * An important note: do _not_ create a parent element. Any element |
|
| 91 | + * implementing XmlSerializble should only ever write what's considered |
|
| 92 | + * its 'inner xml'. |
|
| 93 | + * |
|
| 94 | + * The parent of the current element is responsible for writing a |
|
| 95 | + * containing element. |
|
| 96 | + * |
|
| 97 | + * This allows serializers to be re-used for different element names. |
|
| 98 | + * |
|
| 99 | + * If you are opening new elements, you must also close them again. |
|
| 100 | + * |
|
| 101 | + * @param Writer $writer |
|
| 102 | + * @return void |
|
| 103 | + */ |
|
| 104 | + public function xmlSerialize(Writer $writer) { |
|
| 105 | + |
|
| 106 | + foreach ($this->getHrefs() as $href) { |
|
| 107 | + if ($this->autoPrefix) { |
|
| 108 | + $href = $writer->contextUri . \Sabre\HTTP\encodePath($href); |
|
| 109 | + } |
|
| 110 | + $writer->writeElement('{DAV:}href', $href); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * Generate html representation for this value. |
|
| 117 | + * |
|
| 118 | + * The html output is 100% trusted, and no effort is being made to sanitize |
|
| 119 | + * it. It's up to the implementor to sanitize user provided values. |
|
| 120 | + * |
|
| 121 | + * The output must be in UTF-8. |
|
| 122 | + * |
|
| 123 | + * The baseUri parameter is a url to the root of the application, and can |
|
| 124 | + * be used to construct local links. |
|
| 125 | + * |
|
| 126 | + * @param HtmlOutputHelper $html |
|
| 127 | + * @return string |
|
| 128 | + */ |
|
| 129 | + public function toHtml(HtmlOutputHelper $html) { |
|
| 130 | + |
|
| 131 | + $links = []; |
|
| 132 | + foreach ($this->getHrefs() as $href) { |
|
| 133 | + $links[] = $html->link($href); |
|
| 134 | + } |
|
| 135 | + return implode('<br />', $links); |
|
| 136 | + |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * The deserialize method is called during xml parsing. |
|
| 141 | + * |
|
| 142 | + * This method is called statictly, this is because in theory this method |
|
| 143 | + * may be used as a type of constructor, or factory method. |
|
| 144 | + * |
|
| 145 | + * Often you want to return an instance of the current class, but you are |
|
| 146 | + * free to return other data as well. |
|
| 147 | + * |
|
| 148 | + * You are responsible for advancing the reader to the next element. Not |
|
| 149 | + * doing anything will result in a never-ending loop. |
|
| 150 | + * |
|
| 151 | + * If you just want to skip parsing for this element altogether, you can |
|
| 152 | + * just call $reader->next(); |
|
| 153 | + * |
|
| 154 | + * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
| 155 | + * the next element. |
|
| 156 | + * |
|
| 157 | + * @param Reader $reader |
|
| 158 | + * @return mixed |
|
| 159 | + */ |
|
| 160 | + static function xmlDeserialize(Reader $reader) { |
|
| 161 | + |
|
| 162 | + $hrefs = []; |
|
| 163 | + foreach ((array)$reader->parseInnerTree() as $elem) { |
|
| 164 | + if ($elem['name'] !== '{DAV:}href') |
|
| 165 | + continue; |
|
| 166 | + |
|
| 167 | + $hrefs[] = $elem['value']; |
|
| 168 | + |
|
| 169 | + } |
|
| 170 | + if ($hrefs) { |
|
| 171 | + return new self($hrefs, false); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + } |
|
| 175 | 175 | |
| 176 | 176 | } |
@@ -17,73 +17,73 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class Complex extends XmlFragment { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * The deserialize method is called during xml parsing. |
|
| 22 | - * |
|
| 23 | - * This method is called statictly, this is because in theory this method |
|
| 24 | - * may be used as a type of constructor, or factory method. |
|
| 25 | - * |
|
| 26 | - * Often you want to return an instance of the current class, but you are |
|
| 27 | - * free to return other data as well. |
|
| 28 | - * |
|
| 29 | - * You are responsible for advancing the reader to the next element. Not |
|
| 30 | - * doing anything will result in a never-ending loop. |
|
| 31 | - * |
|
| 32 | - * If you just want to skip parsing for this element altogether, you can |
|
| 33 | - * just call $reader->next(); |
|
| 34 | - * |
|
| 35 | - * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
| 36 | - * the next element. |
|
| 37 | - * |
|
| 38 | - * @param Reader $reader |
|
| 39 | - * @return mixed |
|
| 40 | - */ |
|
| 41 | - static function xmlDeserialize(Reader $reader) { |
|
| 20 | + /** |
|
| 21 | + * The deserialize method is called during xml parsing. |
|
| 22 | + * |
|
| 23 | + * This method is called statictly, this is because in theory this method |
|
| 24 | + * may be used as a type of constructor, or factory method. |
|
| 25 | + * |
|
| 26 | + * Often you want to return an instance of the current class, but you are |
|
| 27 | + * free to return other data as well. |
|
| 28 | + * |
|
| 29 | + * You are responsible for advancing the reader to the next element. Not |
|
| 30 | + * doing anything will result in a never-ending loop. |
|
| 31 | + * |
|
| 32 | + * If you just want to skip parsing for this element altogether, you can |
|
| 33 | + * just call $reader->next(); |
|
| 34 | + * |
|
| 35 | + * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
| 36 | + * the next element. |
|
| 37 | + * |
|
| 38 | + * @param Reader $reader |
|
| 39 | + * @return mixed |
|
| 40 | + */ |
|
| 41 | + static function xmlDeserialize(Reader $reader) { |
|
| 42 | 42 | |
| 43 | - $xml = $reader->readInnerXml(); |
|
| 43 | + $xml = $reader->readInnerXml(); |
|
| 44 | 44 | |
| 45 | - if ($reader->nodeType === Reader::ELEMENT && $reader->isEmptyElement) { |
|
| 46 | - // Easy! |
|
| 47 | - $reader->next(); |
|
| 48 | - return null; |
|
| 49 | - } |
|
| 50 | - // Now we have a copy of the inner xml, we need to traverse it to get |
|
| 51 | - // all the strings. If there's no non-string data, we just return the |
|
| 52 | - // string, otherwise we return an instance of this class. |
|
| 53 | - $reader->read(); |
|
| 45 | + if ($reader->nodeType === Reader::ELEMENT && $reader->isEmptyElement) { |
|
| 46 | + // Easy! |
|
| 47 | + $reader->next(); |
|
| 48 | + return null; |
|
| 49 | + } |
|
| 50 | + // Now we have a copy of the inner xml, we need to traverse it to get |
|
| 51 | + // all the strings. If there's no non-string data, we just return the |
|
| 52 | + // string, otherwise we return an instance of this class. |
|
| 53 | + $reader->read(); |
|
| 54 | 54 | |
| 55 | - $nonText = false; |
|
| 56 | - $text = ''; |
|
| 55 | + $nonText = false; |
|
| 56 | + $text = ''; |
|
| 57 | 57 | |
| 58 | - while (true) { |
|
| 58 | + while (true) { |
|
| 59 | 59 | |
| 60 | - switch ($reader->nodeType) { |
|
| 61 | - case Reader::ELEMENT : |
|
| 62 | - $nonText = true; |
|
| 63 | - $reader->next(); |
|
| 64 | - continue 2; |
|
| 65 | - case Reader::TEXT : |
|
| 66 | - case Reader::CDATA : |
|
| 67 | - $text .= $reader->value; |
|
| 68 | - break; |
|
| 69 | - case Reader::END_ELEMENT : |
|
| 70 | - break 2; |
|
| 71 | - } |
|
| 72 | - $reader->read(); |
|
| 60 | + switch ($reader->nodeType) { |
|
| 61 | + case Reader::ELEMENT : |
|
| 62 | + $nonText = true; |
|
| 63 | + $reader->next(); |
|
| 64 | + continue 2; |
|
| 65 | + case Reader::TEXT : |
|
| 66 | + case Reader::CDATA : |
|
| 67 | + $text .= $reader->value; |
|
| 68 | + break; |
|
| 69 | + case Reader::END_ELEMENT : |
|
| 70 | + break 2; |
|
| 71 | + } |
|
| 72 | + $reader->read(); |
|
| 73 | 73 | |
| 74 | - } |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - // Make sure we advance the cursor one step further. |
|
| 77 | - $reader->read(); |
|
| 76 | + // Make sure we advance the cursor one step further. |
|
| 77 | + $reader->read(); |
|
| 78 | 78 | |
| 79 | - if ($nonText) { |
|
| 80 | - $new = new self($xml); |
|
| 81 | - return $new; |
|
| 82 | - } else { |
|
| 83 | - return $text; |
|
| 84 | - } |
|
| 79 | + if ($nonText) { |
|
| 80 | + $new = new self($xml); |
|
| 81 | + return $new; |
|
| 82 | + } else { |
|
| 83 | + return $text; |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - } |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | 88 | |
| 89 | 89 | } |
@@ -234,12 +234,12 @@ |
||
| 234 | 234 | break; |
| 235 | 235 | case '{DAV:}propstat' : |
| 236 | 236 | $status = $elem['value']['{DAV:}status']; |
| 237 | - list(, $status, ) = explode(' ', $status, 3); |
|
| 237 | + list(, $status,) = explode(' ', $status, 3); |
|
| 238 | 238 | $properties = isset($elem['value']['{DAV:}prop']) ? $elem['value']['{DAV:}prop'] : []; |
| 239 | 239 | if ($properties) $propertyLists[$status] = $properties; |
| 240 | 240 | break; |
| 241 | 241 | case '{DAV:}status' : |
| 242 | - list(, $statusCode, ) = explode(' ', $elem['value'], 3); |
|
| 242 | + list(, $statusCode,) = explode(' ', $elem['value'], 3); |
|
| 243 | 243 | break; |
| 244 | 244 | |
| 245 | 245 | } |
@@ -236,7 +236,9 @@ |
||
| 236 | 236 | $status = $elem['value']['{DAV:}status']; |
| 237 | 237 | list(, $status, ) = explode(' ', $status, 3); |
| 238 | 238 | $properties = isset($elem['value']['{DAV:}prop']) ? $elem['value']['{DAV:}prop'] : []; |
| 239 | - if ($properties) $propertyLists[$status] = $properties; |
|
| 239 | + if ($properties) { |
|
| 240 | + $propertyLists[$status] = $properties; |
|
| 241 | + } |
|
| 240 | 242 | break; |
| 241 | 243 | case '{DAV:}status' : |
| 242 | 244 | list(, $statusCode, ) = explode(' ', $elem['value'], 3); |
@@ -19,128 +19,128 @@ discard block |
||
| 19 | 19 | */ |
| 20 | 20 | class Response implements Element { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * Url for the response |
|
| 24 | - * |
|
| 25 | - * @var string |
|
| 26 | - */ |
|
| 27 | - protected $href; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Propertylist, ordered by HTTP status code |
|
| 31 | - * |
|
| 32 | - * @var array |
|
| 33 | - */ |
|
| 34 | - protected $responseProperties; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * The HTTP status for an entire response. |
|
| 38 | - * |
|
| 39 | - * This is currently only used in WebDAV-Sync |
|
| 40 | - * |
|
| 41 | - * @var string |
|
| 42 | - */ |
|
| 43 | - protected $httpStatus; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * The href argument is a url relative to the root of the server. This |
|
| 47 | - * class will calculate the full path. |
|
| 48 | - * |
|
| 49 | - * The responseProperties argument is a list of properties |
|
| 50 | - * within an array with keys representing HTTP status codes |
|
| 51 | - * |
|
| 52 | - * Besides specific properties, the entire {DAV:}response element may also |
|
| 53 | - * have a http status code. |
|
| 54 | - * In most cases you don't need it. |
|
| 55 | - * |
|
| 56 | - * This is currently used by the Sync extension to indicate that a node is |
|
| 57 | - * deleted. |
|
| 58 | - * |
|
| 59 | - * @param string $href |
|
| 60 | - * @param array $responseProperties |
|
| 61 | - * @param string $httpStatus |
|
| 62 | - */ |
|
| 63 | - public function __construct($href, array $responseProperties, $httpStatus = null) { |
|
| 64 | - |
|
| 65 | - $this->href = $href; |
|
| 66 | - $this->responseProperties = $responseProperties; |
|
| 67 | - $this->httpStatus = $httpStatus; |
|
| 68 | - |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * Returns the url |
|
| 73 | - * |
|
| 74 | - * @return string |
|
| 75 | - */ |
|
| 76 | - public function getHref() { |
|
| 77 | - |
|
| 78 | - return $this->href; |
|
| 79 | - |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * Returns the httpStatus value |
|
| 84 | - * |
|
| 85 | - * @return string |
|
| 86 | - */ |
|
| 87 | - public function getHttpStatus() { |
|
| 88 | - |
|
| 89 | - return $this->httpStatus; |
|
| 90 | - |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Returns the property list |
|
| 95 | - * |
|
| 96 | - * @return array |
|
| 97 | - */ |
|
| 98 | - public function getResponseProperties() { |
|
| 99 | - |
|
| 100 | - return $this->responseProperties; |
|
| 101 | - |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * The serialize method is called during xml writing. |
|
| 107 | - * |
|
| 108 | - * It should use the $writer argument to encode this object into XML. |
|
| 109 | - * |
|
| 110 | - * Important note: it is not needed to create the parent element. The |
|
| 111 | - * parent element is already created, and we only have to worry about |
|
| 112 | - * attributes, child elements and text (if any). |
|
| 113 | - * |
|
| 114 | - * Important note 2: If you are writing any new elements, you are also |
|
| 115 | - * responsible for closing them. |
|
| 116 | - * |
|
| 117 | - * @param Writer $writer |
|
| 118 | - * @return void |
|
| 119 | - */ |
|
| 120 | - public function xmlSerialize(Writer $writer) { |
|
| 121 | - |
|
| 122 | - if ($status = $this->getHTTPStatus()) { |
|
| 123 | - $writer->writeElement('{DAV:}status', 'HTTP/1.1 ' . $status . ' ' . \Sabre\HTTP\Response::$statusCodes[$status]); |
|
| 124 | - } |
|
| 125 | - $writer->writeElement('{DAV:}href', $writer->contextUri . \Sabre\HTTP\encodePath($this->getHref())); |
|
| 126 | - |
|
| 127 | - $empty = true; |
|
| 128 | - |
|
| 129 | - foreach ($this->getResponseProperties() as $status => $properties) { |
|
| 130 | - |
|
| 131 | - // Skipping empty lists |
|
| 132 | - if (!$properties || (!ctype_digit($status) && !is_int($status))) { |
|
| 133 | - continue; |
|
| 134 | - } |
|
| 135 | - $empty = false; |
|
| 136 | - $writer->startElement('{DAV:}propstat'); |
|
| 137 | - $writer->writeElement('{DAV:}prop', $properties); |
|
| 138 | - $writer->writeElement('{DAV:}status', 'HTTP/1.1 ' . $status . ' ' . \Sabre\HTTP\Response::$statusCodes[$status]); |
|
| 139 | - $writer->endElement(); // {DAV:}propstat |
|
| 140 | - |
|
| 141 | - } |
|
| 142 | - if ($empty) { |
|
| 143 | - /* |
|
| 22 | + /** |
|
| 23 | + * Url for the response |
|
| 24 | + * |
|
| 25 | + * @var string |
|
| 26 | + */ |
|
| 27 | + protected $href; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Propertylist, ordered by HTTP status code |
|
| 31 | + * |
|
| 32 | + * @var array |
|
| 33 | + */ |
|
| 34 | + protected $responseProperties; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * The HTTP status for an entire response. |
|
| 38 | + * |
|
| 39 | + * This is currently only used in WebDAV-Sync |
|
| 40 | + * |
|
| 41 | + * @var string |
|
| 42 | + */ |
|
| 43 | + protected $httpStatus; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * The href argument is a url relative to the root of the server. This |
|
| 47 | + * class will calculate the full path. |
|
| 48 | + * |
|
| 49 | + * The responseProperties argument is a list of properties |
|
| 50 | + * within an array with keys representing HTTP status codes |
|
| 51 | + * |
|
| 52 | + * Besides specific properties, the entire {DAV:}response element may also |
|
| 53 | + * have a http status code. |
|
| 54 | + * In most cases you don't need it. |
|
| 55 | + * |
|
| 56 | + * This is currently used by the Sync extension to indicate that a node is |
|
| 57 | + * deleted. |
|
| 58 | + * |
|
| 59 | + * @param string $href |
|
| 60 | + * @param array $responseProperties |
|
| 61 | + * @param string $httpStatus |
|
| 62 | + */ |
|
| 63 | + public function __construct($href, array $responseProperties, $httpStatus = null) { |
|
| 64 | + |
|
| 65 | + $this->href = $href; |
|
| 66 | + $this->responseProperties = $responseProperties; |
|
| 67 | + $this->httpStatus = $httpStatus; |
|
| 68 | + |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * Returns the url |
|
| 73 | + * |
|
| 74 | + * @return string |
|
| 75 | + */ |
|
| 76 | + public function getHref() { |
|
| 77 | + |
|
| 78 | + return $this->href; |
|
| 79 | + |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * Returns the httpStatus value |
|
| 84 | + * |
|
| 85 | + * @return string |
|
| 86 | + */ |
|
| 87 | + public function getHttpStatus() { |
|
| 88 | + |
|
| 89 | + return $this->httpStatus; |
|
| 90 | + |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Returns the property list |
|
| 95 | + * |
|
| 96 | + * @return array |
|
| 97 | + */ |
|
| 98 | + public function getResponseProperties() { |
|
| 99 | + |
|
| 100 | + return $this->responseProperties; |
|
| 101 | + |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * The serialize method is called during xml writing. |
|
| 107 | + * |
|
| 108 | + * It should use the $writer argument to encode this object into XML. |
|
| 109 | + * |
|
| 110 | + * Important note: it is not needed to create the parent element. The |
|
| 111 | + * parent element is already created, and we only have to worry about |
|
| 112 | + * attributes, child elements and text (if any). |
|
| 113 | + * |
|
| 114 | + * Important note 2: If you are writing any new elements, you are also |
|
| 115 | + * responsible for closing them. |
|
| 116 | + * |
|
| 117 | + * @param Writer $writer |
|
| 118 | + * @return void |
|
| 119 | + */ |
|
| 120 | + public function xmlSerialize(Writer $writer) { |
|
| 121 | + |
|
| 122 | + if ($status = $this->getHTTPStatus()) { |
|
| 123 | + $writer->writeElement('{DAV:}status', 'HTTP/1.1 ' . $status . ' ' . \Sabre\HTTP\Response::$statusCodes[$status]); |
|
| 124 | + } |
|
| 125 | + $writer->writeElement('{DAV:}href', $writer->contextUri . \Sabre\HTTP\encodePath($this->getHref())); |
|
| 126 | + |
|
| 127 | + $empty = true; |
|
| 128 | + |
|
| 129 | + foreach ($this->getResponseProperties() as $status => $properties) { |
|
| 130 | + |
|
| 131 | + // Skipping empty lists |
|
| 132 | + if (!$properties || (!ctype_digit($status) && !is_int($status))) { |
|
| 133 | + continue; |
|
| 134 | + } |
|
| 135 | + $empty = false; |
|
| 136 | + $writer->startElement('{DAV:}propstat'); |
|
| 137 | + $writer->writeElement('{DAV:}prop', $properties); |
|
| 138 | + $writer->writeElement('{DAV:}status', 'HTTP/1.1 ' . $status . ' ' . \Sabre\HTTP\Response::$statusCodes[$status]); |
|
| 139 | + $writer->endElement(); // {DAV:}propstat |
|
| 140 | + |
|
| 141 | + } |
|
| 142 | + if ($empty) { |
|
| 143 | + /* |
|
| 144 | 144 | * The WebDAV spec _requires_ at least one DAV:propstat to appear for |
| 145 | 145 | * every DAV:response. In some circumstances however, there are no |
| 146 | 146 | * properties to encode. |
@@ -148,106 +148,106 @@ discard block |
||
| 148 | 148 | * In those cases we MUST specify at least one DAV:propstat anyway, with |
| 149 | 149 | * no properties. |
| 150 | 150 | */ |
| 151 | - $writer->writeElement('{DAV:}propstat', [ |
|
| 152 | - '{DAV:}prop' => [], |
|
| 153 | - '{DAV:}status' => 'HTTP/1.1 418 ' . \Sabre\HTTP\Response::$statusCodes[418] |
|
| 154 | - ]); |
|
| 155 | - |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * The deserialize method is called during xml parsing. |
|
| 162 | - * |
|
| 163 | - * This method is called statictly, this is because in theory this method |
|
| 164 | - * may be used as a type of constructor, or factory method. |
|
| 165 | - * |
|
| 166 | - * Often you want to return an instance of the current class, but you are |
|
| 167 | - * free to return other data as well. |
|
| 168 | - * |
|
| 169 | - * You are responsible for advancing the reader to the next element. Not |
|
| 170 | - * doing anything will result in a never-ending loop. |
|
| 171 | - * |
|
| 172 | - * If you just want to skip parsing for this element altogether, you can |
|
| 173 | - * just call $reader->next(); |
|
| 174 | - * |
|
| 175 | - * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
| 176 | - * the next element. |
|
| 177 | - * |
|
| 178 | - * @param Reader $reader |
|
| 179 | - * @return mixed |
|
| 180 | - */ |
|
| 181 | - static function xmlDeserialize(Reader $reader) { |
|
| 182 | - |
|
| 183 | - $reader->pushContext(); |
|
| 184 | - |
|
| 185 | - $reader->elementMap['{DAV:}propstat'] = 'Sabre\\Xml\\Element\\KeyValue'; |
|
| 186 | - |
|
| 187 | - // We are overriding the parser for {DAV:}prop. This deserializer is |
|
| 188 | - // almost identical to the one for Sabre\Xml\Element\KeyValue. |
|
| 189 | - // |
|
| 190 | - // The difference is that if there are any child-elements inside of |
|
| 191 | - // {DAV:}prop, that have no value, normally any deserializers are |
|
| 192 | - // called. But we don't want this, because a singular element without |
|
| 193 | - // child-elements implies 'no value' in {DAV:}prop, so we want to skip |
|
| 194 | - // deserializers and just set null for those. |
|
| 195 | - $reader->elementMap['{DAV:}prop'] = function(Reader $reader) { |
|
| 196 | - |
|
| 197 | - if ($reader->isEmptyElement) { |
|
| 198 | - $reader->next(); |
|
| 199 | - return []; |
|
| 200 | - } |
|
| 201 | - $values = []; |
|
| 202 | - $reader->read(); |
|
| 203 | - do { |
|
| 204 | - if ($reader->nodeType === Reader::ELEMENT) { |
|
| 205 | - $clark = $reader->getClark(); |
|
| 206 | - |
|
| 207 | - if ($reader->isEmptyElement) { |
|
| 208 | - $values[$clark] = null; |
|
| 209 | - $reader->next(); |
|
| 210 | - } else { |
|
| 211 | - $values[$clark] = $reader->parseCurrentElement()['value']; |
|
| 212 | - } |
|
| 213 | - } else { |
|
| 214 | - $reader->read(); |
|
| 215 | - } |
|
| 216 | - } while ($reader->nodeType !== Reader::END_ELEMENT); |
|
| 217 | - $reader->read(); |
|
| 218 | - return $values; |
|
| 219 | - |
|
| 220 | - }; |
|
| 221 | - $elems = $reader->parseInnerTree(); |
|
| 222 | - $reader->popContext(); |
|
| 223 | - |
|
| 224 | - $href = null; |
|
| 225 | - $propertyLists = []; |
|
| 226 | - $statusCode = null; |
|
| 227 | - |
|
| 228 | - foreach ($elems as $elem) { |
|
| 229 | - |
|
| 230 | - switch ($elem['name']) { |
|
| 231 | - |
|
| 232 | - case '{DAV:}href' : |
|
| 233 | - $href = $elem['value']; |
|
| 234 | - break; |
|
| 235 | - case '{DAV:}propstat' : |
|
| 236 | - $status = $elem['value']['{DAV:}status']; |
|
| 237 | - list(, $status, ) = explode(' ', $status, 3); |
|
| 238 | - $properties = isset($elem['value']['{DAV:}prop']) ? $elem['value']['{DAV:}prop'] : []; |
|
| 239 | - if ($properties) $propertyLists[$status] = $properties; |
|
| 240 | - break; |
|
| 241 | - case '{DAV:}status' : |
|
| 242 | - list(, $statusCode, ) = explode(' ', $elem['value'], 3); |
|
| 243 | - break; |
|
| 244 | - |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - return new self($href, $propertyLists, $statusCode); |
|
| 250 | - |
|
| 251 | - } |
|
| 151 | + $writer->writeElement('{DAV:}propstat', [ |
|
| 152 | + '{DAV:}prop' => [], |
|
| 153 | + '{DAV:}status' => 'HTTP/1.1 418 ' . \Sabre\HTTP\Response::$statusCodes[418] |
|
| 154 | + ]); |
|
| 155 | + |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * The deserialize method is called during xml parsing. |
|
| 162 | + * |
|
| 163 | + * This method is called statictly, this is because in theory this method |
|
| 164 | + * may be used as a type of constructor, or factory method. |
|
| 165 | + * |
|
| 166 | + * Often you want to return an instance of the current class, but you are |
|
| 167 | + * free to return other data as well. |
|
| 168 | + * |
|
| 169 | + * You are responsible for advancing the reader to the next element. Not |
|
| 170 | + * doing anything will result in a never-ending loop. |
|
| 171 | + * |
|
| 172 | + * If you just want to skip parsing for this element altogether, you can |
|
| 173 | + * just call $reader->next(); |
|
| 174 | + * |
|
| 175 | + * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
| 176 | + * the next element. |
|
| 177 | + * |
|
| 178 | + * @param Reader $reader |
|
| 179 | + * @return mixed |
|
| 180 | + */ |
|
| 181 | + static function xmlDeserialize(Reader $reader) { |
|
| 182 | + |
|
| 183 | + $reader->pushContext(); |
|
| 184 | + |
|
| 185 | + $reader->elementMap['{DAV:}propstat'] = 'Sabre\\Xml\\Element\\KeyValue'; |
|
| 186 | + |
|
| 187 | + // We are overriding the parser for {DAV:}prop. This deserializer is |
|
| 188 | + // almost identical to the one for Sabre\Xml\Element\KeyValue. |
|
| 189 | + // |
|
| 190 | + // The difference is that if there are any child-elements inside of |
|
| 191 | + // {DAV:}prop, that have no value, normally any deserializers are |
|
| 192 | + // called. But we don't want this, because a singular element without |
|
| 193 | + // child-elements implies 'no value' in {DAV:}prop, so we want to skip |
|
| 194 | + // deserializers and just set null for those. |
|
| 195 | + $reader->elementMap['{DAV:}prop'] = function(Reader $reader) { |
|
| 196 | + |
|
| 197 | + if ($reader->isEmptyElement) { |
|
| 198 | + $reader->next(); |
|
| 199 | + return []; |
|
| 200 | + } |
|
| 201 | + $values = []; |
|
| 202 | + $reader->read(); |
|
| 203 | + do { |
|
| 204 | + if ($reader->nodeType === Reader::ELEMENT) { |
|
| 205 | + $clark = $reader->getClark(); |
|
| 206 | + |
|
| 207 | + if ($reader->isEmptyElement) { |
|
| 208 | + $values[$clark] = null; |
|
| 209 | + $reader->next(); |
|
| 210 | + } else { |
|
| 211 | + $values[$clark] = $reader->parseCurrentElement()['value']; |
|
| 212 | + } |
|
| 213 | + } else { |
|
| 214 | + $reader->read(); |
|
| 215 | + } |
|
| 216 | + } while ($reader->nodeType !== Reader::END_ELEMENT); |
|
| 217 | + $reader->read(); |
|
| 218 | + return $values; |
|
| 219 | + |
|
| 220 | + }; |
|
| 221 | + $elems = $reader->parseInnerTree(); |
|
| 222 | + $reader->popContext(); |
|
| 223 | + |
|
| 224 | + $href = null; |
|
| 225 | + $propertyLists = []; |
|
| 226 | + $statusCode = null; |
|
| 227 | + |
|
| 228 | + foreach ($elems as $elem) { |
|
| 229 | + |
|
| 230 | + switch ($elem['name']) { |
|
| 231 | + |
|
| 232 | + case '{DAV:}href' : |
|
| 233 | + $href = $elem['value']; |
|
| 234 | + break; |
|
| 235 | + case '{DAV:}propstat' : |
|
| 236 | + $status = $elem['value']['{DAV:}status']; |
|
| 237 | + list(, $status, ) = explode(' ', $status, 3); |
|
| 238 | + $properties = isset($elem['value']['{DAV:}prop']) ? $elem['value']['{DAV:}prop'] : []; |
|
| 239 | + if ($properties) $propertyLists[$status] = $properties; |
|
| 240 | + break; |
|
| 241 | + case '{DAV:}status' : |
|
| 242 | + list(, $statusCode, ) = explode(' ', $elem['value'], 3); |
|
| 243 | + break; |
|
| 244 | + |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + return new self($href, $propertyLists, $statusCode); |
|
| 250 | + |
|
| 251 | + } |
|
| 252 | 252 | |
| 253 | 253 | } |
@@ -19,98 +19,98 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | class Prop implements XmlDeserializable { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * The deserialize method is called during xml parsing. |
|
| 24 | - * |
|
| 25 | - * This method is called statictly, this is because in theory this method |
|
| 26 | - * may be used as a type of constructor, or factory method. |
|
| 27 | - * |
|
| 28 | - * Often you want to return an instance of the current class, but you are |
|
| 29 | - * free to return other data as well. |
|
| 30 | - * |
|
| 31 | - * You are responsible for advancing the reader to the next element. Not |
|
| 32 | - * doing anything will result in a never-ending loop. |
|
| 33 | - * |
|
| 34 | - * If you just want to skip parsing for this element altogether, you can |
|
| 35 | - * just call $reader->next(); |
|
| 36 | - * |
|
| 37 | - * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
| 38 | - * the next element. |
|
| 39 | - * |
|
| 40 | - * @param Reader $reader |
|
| 41 | - * @return mixed |
|
| 42 | - */ |
|
| 43 | - static function xmlDeserialize(Reader $reader) { |
|
| 44 | - |
|
| 45 | - // If there's no children, we don't do anything. |
|
| 46 | - if ($reader->isEmptyElement) { |
|
| 47 | - $reader->next(); |
|
| 48 | - return []; |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - $values = []; |
|
| 52 | - |
|
| 53 | - $reader->read(); |
|
| 54 | - do { |
|
| 55 | - |
|
| 56 | - if ($reader->nodeType === Reader::ELEMENT) { |
|
| 57 | - |
|
| 58 | - $clark = $reader->getClark(); |
|
| 59 | - $values[$clark] = self::parseCurrentElement($reader)['value']; |
|
| 60 | - |
|
| 61 | - } else { |
|
| 62 | - $reader->read(); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - } while ($reader->nodeType !== Reader::END_ELEMENT); |
|
| 66 | - |
|
| 67 | - $reader->read(); |
|
| 68 | - |
|
| 69 | - return $values; |
|
| 70 | - |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * This function behaves similar to Sabre\Xml\Reader::parseCurrentElement, |
|
| 75 | - * but instead of creating deep xml array structures, it will turn any |
|
| 76 | - * top-level element it doesn't recognize into either a string, or an |
|
| 77 | - * XmlFragment class. |
|
| 78 | - * |
|
| 79 | - * This method returns arn array with 2 properties: |
|
| 80 | - * * name - A clark-notation XML element name. |
|
| 81 | - * * value - The parsed value. |
|
| 82 | - * |
|
| 83 | - * @param Reader $reader |
|
| 84 | - * @return array |
|
| 85 | - */ |
|
| 86 | - private static function parseCurrentElement(Reader $reader) { |
|
| 87 | - |
|
| 88 | - $name = $reader->getClark(); |
|
| 89 | - |
|
| 90 | - if (array_key_exists($name, $reader->elementMap)) { |
|
| 91 | - $deserializer = $reader->elementMap[$name]; |
|
| 92 | - if (is_subclass_of($deserializer, 'Sabre\\Xml\\XmlDeserializable')) { |
|
| 93 | - $value = call_user_func([ $deserializer, 'xmlDeserialize' ], $reader); |
|
| 94 | - } elseif (is_callable($deserializer)) { |
|
| 95 | - $value = call_user_func($deserializer, $reader); |
|
| 96 | - } else { |
|
| 97 | - $type = gettype($deserializer); |
|
| 98 | - if ($type === 'string') { |
|
| 99 | - $type .= ' (' . $deserializer . ')'; |
|
| 100 | - } elseif ($type === 'object') { |
|
| 101 | - $type .= ' (' . get_class($deserializer) . ')'; |
|
| 102 | - } |
|
| 103 | - throw new \LogicException('Could not use this type as a deserializer: ' . $type); |
|
| 104 | - } |
|
| 105 | - } else { |
|
| 106 | - $value = Complex::xmlDeserialize($reader); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - return [ |
|
| 110 | - 'name' => $name, |
|
| 111 | - 'value' => $value, |
|
| 112 | - ]; |
|
| 113 | - |
|
| 114 | - } |
|
| 22 | + /** |
|
| 23 | + * The deserialize method is called during xml parsing. |
|
| 24 | + * |
|
| 25 | + * This method is called statictly, this is because in theory this method |
|
| 26 | + * may be used as a type of constructor, or factory method. |
|
| 27 | + * |
|
| 28 | + * Often you want to return an instance of the current class, but you are |
|
| 29 | + * free to return other data as well. |
|
| 30 | + * |
|
| 31 | + * You are responsible for advancing the reader to the next element. Not |
|
| 32 | + * doing anything will result in a never-ending loop. |
|
| 33 | + * |
|
| 34 | + * If you just want to skip parsing for this element altogether, you can |
|
| 35 | + * just call $reader->next(); |
|
| 36 | + * |
|
| 37 | + * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
| 38 | + * the next element. |
|
| 39 | + * |
|
| 40 | + * @param Reader $reader |
|
| 41 | + * @return mixed |
|
| 42 | + */ |
|
| 43 | + static function xmlDeserialize(Reader $reader) { |
|
| 44 | + |
|
| 45 | + // If there's no children, we don't do anything. |
|
| 46 | + if ($reader->isEmptyElement) { |
|
| 47 | + $reader->next(); |
|
| 48 | + return []; |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + $values = []; |
|
| 52 | + |
|
| 53 | + $reader->read(); |
|
| 54 | + do { |
|
| 55 | + |
|
| 56 | + if ($reader->nodeType === Reader::ELEMENT) { |
|
| 57 | + |
|
| 58 | + $clark = $reader->getClark(); |
|
| 59 | + $values[$clark] = self::parseCurrentElement($reader)['value']; |
|
| 60 | + |
|
| 61 | + } else { |
|
| 62 | + $reader->read(); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + } while ($reader->nodeType !== Reader::END_ELEMENT); |
|
| 66 | + |
|
| 67 | + $reader->read(); |
|
| 68 | + |
|
| 69 | + return $values; |
|
| 70 | + |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * This function behaves similar to Sabre\Xml\Reader::parseCurrentElement, |
|
| 75 | + * but instead of creating deep xml array structures, it will turn any |
|
| 76 | + * top-level element it doesn't recognize into either a string, or an |
|
| 77 | + * XmlFragment class. |
|
| 78 | + * |
|
| 79 | + * This method returns arn array with 2 properties: |
|
| 80 | + * * name - A clark-notation XML element name. |
|
| 81 | + * * value - The parsed value. |
|
| 82 | + * |
|
| 83 | + * @param Reader $reader |
|
| 84 | + * @return array |
|
| 85 | + */ |
|
| 86 | + private static function parseCurrentElement(Reader $reader) { |
|
| 87 | + |
|
| 88 | + $name = $reader->getClark(); |
|
| 89 | + |
|
| 90 | + if (array_key_exists($name, $reader->elementMap)) { |
|
| 91 | + $deserializer = $reader->elementMap[$name]; |
|
| 92 | + if (is_subclass_of($deserializer, 'Sabre\\Xml\\XmlDeserializable')) { |
|
| 93 | + $value = call_user_func([ $deserializer, 'xmlDeserialize' ], $reader); |
|
| 94 | + } elseif (is_callable($deserializer)) { |
|
| 95 | + $value = call_user_func($deserializer, $reader); |
|
| 96 | + } else { |
|
| 97 | + $type = gettype($deserializer); |
|
| 98 | + if ($type === 'string') { |
|
| 99 | + $type .= ' (' . $deserializer . ')'; |
|
| 100 | + } elseif ($type === 'object') { |
|
| 101 | + $type .= ' (' . get_class($deserializer) . ')'; |
|
| 102 | + } |
|
| 103 | + throw new \LogicException('Could not use this type as a deserializer: ' . $type); |
|
| 104 | + } |
|
| 105 | + } else { |
|
| 106 | + $value = Complex::xmlDeserialize($reader); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + return [ |
|
| 110 | + 'name' => $name, |
|
| 111 | + 'value' => $value, |
|
| 112 | + ]; |
|
| 113 | + |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | 116 | } |
@@ -90,7 +90,7 @@ |
||
| 90 | 90 | if (array_key_exists($name, $reader->elementMap)) { |
| 91 | 91 | $deserializer = $reader->elementMap[$name]; |
| 92 | 92 | if (is_subclass_of($deserializer, 'Sabre\\Xml\\XmlDeserializable')) { |
| 93 | - $value = call_user_func([ $deserializer, 'xmlDeserialize' ], $reader); |
|
| 93 | + $value = call_user_func([$deserializer, 'xmlDeserialize'], $reader); |
|
| 94 | 94 | } elseif (is_callable($deserializer)) { |
| 95 | 95 | $value = call_user_func($deserializer, $reader); |
| 96 | 96 | } else { |
@@ -11,37 +11,37 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class Service extends \Sabre\Xml\Service { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * This is a list of XML elements that we automatically map to PHP classes. |
|
| 16 | - * |
|
| 17 | - * For instance, this list may contain an entry `{DAV:}propfind` that would |
|
| 18 | - * be mapped to Sabre\DAV\Xml\Request\PropFind |
|
| 19 | - */ |
|
| 20 | - public $elementMap = [ |
|
| 21 | - '{DAV:}multistatus' => 'Sabre\\DAV\\Xml\\Response\\MultiStatus', |
|
| 22 | - '{DAV:}response' => 'Sabre\\DAV\\Xml\\Element\\Response', |
|
| 23 | - |
|
| 24 | - // Requests |
|
| 25 | - '{DAV:}propfind' => 'Sabre\\DAV\\Xml\\Request\\PropFind', |
|
| 26 | - '{DAV:}propertyupdate' => 'Sabre\\DAV\\Xml\\Request\\PropPatch', |
|
| 27 | - '{DAV:}mkcol' => 'Sabre\\DAV\\Xml\\Request\\MkCol', |
|
| 28 | - |
|
| 29 | - // Properties |
|
| 30 | - '{DAV:}resourcetype' => 'Sabre\\DAV\\Xml\\Property\\ResourceType', |
|
| 31 | - |
|
| 32 | - ]; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * This is a default list of namespaces. |
|
| 36 | - * |
|
| 37 | - * If you are defining your own custom namespace, add it here to reduce |
|
| 38 | - * bandwidth and improve legibility of xml bodies. |
|
| 39 | - * |
|
| 40 | - * @var array |
|
| 41 | - */ |
|
| 42 | - public $namespaceMap = [ |
|
| 43 | - 'DAV:' => 'd', |
|
| 44 | - 'http://sabredav.org/ns' => 's', |
|
| 45 | - ]; |
|
| 14 | + /** |
|
| 15 | + * This is a list of XML elements that we automatically map to PHP classes. |
|
| 16 | + * |
|
| 17 | + * For instance, this list may contain an entry `{DAV:}propfind` that would |
|
| 18 | + * be mapped to Sabre\DAV\Xml\Request\PropFind |
|
| 19 | + */ |
|
| 20 | + public $elementMap = [ |
|
| 21 | + '{DAV:}multistatus' => 'Sabre\\DAV\\Xml\\Response\\MultiStatus', |
|
| 22 | + '{DAV:}response' => 'Sabre\\DAV\\Xml\\Element\\Response', |
|
| 23 | + |
|
| 24 | + // Requests |
|
| 25 | + '{DAV:}propfind' => 'Sabre\\DAV\\Xml\\Request\\PropFind', |
|
| 26 | + '{DAV:}propertyupdate' => 'Sabre\\DAV\\Xml\\Request\\PropPatch', |
|
| 27 | + '{DAV:}mkcol' => 'Sabre\\DAV\\Xml\\Request\\MkCol', |
|
| 28 | + |
|
| 29 | + // Properties |
|
| 30 | + '{DAV:}resourcetype' => 'Sabre\\DAV\\Xml\\Property\\ResourceType', |
|
| 31 | + |
|
| 32 | + ]; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * This is a default list of namespaces. |
|
| 36 | + * |
|
| 37 | + * If you are defining your own custom namespace, add it here to reduce |
|
| 38 | + * bandwidth and improve legibility of xml bodies. |
|
| 39 | + * |
|
| 40 | + * @var array |
|
| 41 | + */ |
|
| 42 | + public $namespaceMap = [ |
|
| 43 | + 'DAV:' => 'd', |
|
| 44 | + 'http://sabredav.org/ns' => 's', |
|
| 45 | + ]; |
|
| 46 | 46 | |
| 47 | 47 | } |
@@ -57,11 +57,13 @@ |
||
| 57 | 57 | if (!$principal) { |
| 58 | 58 | throw new DAV\Exception\NotFound('Node with name ' . $name . ' was not found'); |
| 59 | 59 | } |
| 60 | - if ($name === 'calendar-proxy-read') |
|
| 61 | - return new ProxyRead($this->principalBackend, $this->principalProperties); |
|
| 60 | + if ($name === 'calendar-proxy-read') { |
|
| 61 | + return new ProxyRead($this->principalBackend, $this->principalProperties); |
|
| 62 | + } |
|
| 62 | 63 | |
| 63 | - if ($name === 'calendar-proxy-write') |
|
| 64 | - return new ProxyWrite($this->principalBackend, $this->principalProperties); |
|
| 64 | + if ($name === 'calendar-proxy-write') { |
|
| 65 | + return new ProxyWrite($this->principalBackend, $this->principalProperties); |
|
| 66 | + } |
|
| 65 | 67 | |
| 66 | 68 | throw new DAV\Exception\NotFound('Node with name ' . $name . ' was not found'); |
| 67 | 69 | |
@@ -18,118 +18,118 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class User extends DAVACL\Principal implements DAV\ICollection { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Creates a new file in the directory |
|
| 23 | - * |
|
| 24 | - * @param string $name Name of the file |
|
| 25 | - * @param resource $data Initial payload, passed as a readable stream resource. |
|
| 26 | - * @throws DAV\Exception\Forbidden |
|
| 27 | - * @return void |
|
| 28 | - */ |
|
| 29 | - public function createFile($name, $data = null) { |
|
| 30 | - |
|
| 31 | - throw new DAV\Exception\Forbidden('Permission denied to create file (filename ' . $name . ')'); |
|
| 32 | - |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * Creates a new subdirectory |
|
| 37 | - * |
|
| 38 | - * @param string $name |
|
| 39 | - * @throws DAV\Exception\Forbidden |
|
| 40 | - * @return void |
|
| 41 | - */ |
|
| 42 | - public function createDirectory($name) { |
|
| 43 | - |
|
| 44 | - throw new DAV\Exception\Forbidden('Permission denied to create directory'); |
|
| 45 | - |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * Returns a specific child node, referenced by its name |
|
| 50 | - * |
|
| 51 | - * @param string $name |
|
| 52 | - * @return DAV\INode |
|
| 53 | - */ |
|
| 54 | - public function getChild($name) { |
|
| 55 | - |
|
| 56 | - $principal = $this->principalBackend->getPrincipalByPath($this->getPrincipalURL() . '/' . $name); |
|
| 57 | - if (!$principal) { |
|
| 58 | - throw new DAV\Exception\NotFound('Node with name ' . $name . ' was not found'); |
|
| 59 | - } |
|
| 60 | - if ($name === 'calendar-proxy-read') |
|
| 61 | - return new ProxyRead($this->principalBackend, $this->principalProperties); |
|
| 62 | - |
|
| 63 | - if ($name === 'calendar-proxy-write') |
|
| 64 | - return new ProxyWrite($this->principalBackend, $this->principalProperties); |
|
| 65 | - |
|
| 66 | - throw new DAV\Exception\NotFound('Node with name ' . $name . ' was not found'); |
|
| 67 | - |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * Returns an array with all the child nodes |
|
| 72 | - * |
|
| 73 | - * @return DAV\INode[] |
|
| 74 | - */ |
|
| 75 | - public function getChildren() { |
|
| 76 | - |
|
| 77 | - $r = []; |
|
| 78 | - if ($this->principalBackend->getPrincipalByPath($this->getPrincipalURL() . '/calendar-proxy-read')) { |
|
| 79 | - $r[] = new ProxyRead($this->principalBackend, $this->principalProperties); |
|
| 80 | - } |
|
| 81 | - if ($this->principalBackend->getPrincipalByPath($this->getPrincipalURL() . '/calendar-proxy-write')) { |
|
| 82 | - $r[] = new ProxyWrite($this->principalBackend, $this->principalProperties); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - return $r; |
|
| 86 | - |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * Returns whether or not the child node exists |
|
| 91 | - * |
|
| 92 | - * @param string $name |
|
| 93 | - * @return bool |
|
| 94 | - */ |
|
| 95 | - public function childExists($name) { |
|
| 96 | - |
|
| 97 | - try { |
|
| 98 | - $this->getChild($name); |
|
| 99 | - return true; |
|
| 100 | - } catch (DAV\Exception\NotFound $e) { |
|
| 101 | - return false; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * Returns a list of ACE's for this node. |
|
| 108 | - * |
|
| 109 | - * Each ACE has the following properties: |
|
| 110 | - * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are |
|
| 111 | - * currently the only supported privileges |
|
| 112 | - * * 'principal', a url to the principal who owns the node |
|
| 113 | - * * 'protected' (optional), indicating that this ACE is not allowed to |
|
| 114 | - * be updated. |
|
| 115 | - * |
|
| 116 | - * @return array |
|
| 117 | - */ |
|
| 118 | - public function getACL() { |
|
| 119 | - |
|
| 120 | - $acl = parent::getACL(); |
|
| 121 | - $acl[] = [ |
|
| 122 | - 'privilege' => '{DAV:}read', |
|
| 123 | - 'principal' => $this->principalProperties['uri'] . '/calendar-proxy-read', |
|
| 124 | - 'protected' => true, |
|
| 125 | - ]; |
|
| 126 | - $acl[] = [ |
|
| 127 | - 'privilege' => '{DAV:}read', |
|
| 128 | - 'principal' => $this->principalProperties['uri'] . '/calendar-proxy-write', |
|
| 129 | - 'protected' => true, |
|
| 130 | - ]; |
|
| 131 | - return $acl; |
|
| 132 | - |
|
| 133 | - } |
|
| 21 | + /** |
|
| 22 | + * Creates a new file in the directory |
|
| 23 | + * |
|
| 24 | + * @param string $name Name of the file |
|
| 25 | + * @param resource $data Initial payload, passed as a readable stream resource. |
|
| 26 | + * @throws DAV\Exception\Forbidden |
|
| 27 | + * @return void |
|
| 28 | + */ |
|
| 29 | + public function createFile($name, $data = null) { |
|
| 30 | + |
|
| 31 | + throw new DAV\Exception\Forbidden('Permission denied to create file (filename ' . $name . ')'); |
|
| 32 | + |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * Creates a new subdirectory |
|
| 37 | + * |
|
| 38 | + * @param string $name |
|
| 39 | + * @throws DAV\Exception\Forbidden |
|
| 40 | + * @return void |
|
| 41 | + */ |
|
| 42 | + public function createDirectory($name) { |
|
| 43 | + |
|
| 44 | + throw new DAV\Exception\Forbidden('Permission denied to create directory'); |
|
| 45 | + |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * Returns a specific child node, referenced by its name |
|
| 50 | + * |
|
| 51 | + * @param string $name |
|
| 52 | + * @return DAV\INode |
|
| 53 | + */ |
|
| 54 | + public function getChild($name) { |
|
| 55 | + |
|
| 56 | + $principal = $this->principalBackend->getPrincipalByPath($this->getPrincipalURL() . '/' . $name); |
|
| 57 | + if (!$principal) { |
|
| 58 | + throw new DAV\Exception\NotFound('Node with name ' . $name . ' was not found'); |
|
| 59 | + } |
|
| 60 | + if ($name === 'calendar-proxy-read') |
|
| 61 | + return new ProxyRead($this->principalBackend, $this->principalProperties); |
|
| 62 | + |
|
| 63 | + if ($name === 'calendar-proxy-write') |
|
| 64 | + return new ProxyWrite($this->principalBackend, $this->principalProperties); |
|
| 65 | + |
|
| 66 | + throw new DAV\Exception\NotFound('Node with name ' . $name . ' was not found'); |
|
| 67 | + |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * Returns an array with all the child nodes |
|
| 72 | + * |
|
| 73 | + * @return DAV\INode[] |
|
| 74 | + */ |
|
| 75 | + public function getChildren() { |
|
| 76 | + |
|
| 77 | + $r = []; |
|
| 78 | + if ($this->principalBackend->getPrincipalByPath($this->getPrincipalURL() . '/calendar-proxy-read')) { |
|
| 79 | + $r[] = new ProxyRead($this->principalBackend, $this->principalProperties); |
|
| 80 | + } |
|
| 81 | + if ($this->principalBackend->getPrincipalByPath($this->getPrincipalURL() . '/calendar-proxy-write')) { |
|
| 82 | + $r[] = new ProxyWrite($this->principalBackend, $this->principalProperties); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + return $r; |
|
| 86 | + |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * Returns whether or not the child node exists |
|
| 91 | + * |
|
| 92 | + * @param string $name |
|
| 93 | + * @return bool |
|
| 94 | + */ |
|
| 95 | + public function childExists($name) { |
|
| 96 | + |
|
| 97 | + try { |
|
| 98 | + $this->getChild($name); |
|
| 99 | + return true; |
|
| 100 | + } catch (DAV\Exception\NotFound $e) { |
|
| 101 | + return false; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * Returns a list of ACE's for this node. |
|
| 108 | + * |
|
| 109 | + * Each ACE has the following properties: |
|
| 110 | + * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are |
|
| 111 | + * currently the only supported privileges |
|
| 112 | + * * 'principal', a url to the principal who owns the node |
|
| 113 | + * * 'protected' (optional), indicating that this ACE is not allowed to |
|
| 114 | + * be updated. |
|
| 115 | + * |
|
| 116 | + * @return array |
|
| 117 | + */ |
|
| 118 | + public function getACL() { |
|
| 119 | + |
|
| 120 | + $acl = parent::getACL(); |
|
| 121 | + $acl[] = [ |
|
| 122 | + 'privilege' => '{DAV:}read', |
|
| 123 | + 'principal' => $this->principalProperties['uri'] . '/calendar-proxy-read', |
|
| 124 | + 'protected' => true, |
|
| 125 | + ]; |
|
| 126 | + $acl[] = [ |
|
| 127 | + 'privilege' => '{DAV:}read', |
|
| 128 | + 'principal' => $this->principalProperties['uri'] . '/calendar-proxy-write', |
|
| 129 | + 'protected' => true, |
|
| 130 | + ]; |
|
| 131 | + return $acl; |
|
| 132 | + |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | 135 | } |
@@ -95,10 +95,10 @@ |
||
| 95 | 95 | $this->server->xml->elementMap['{' . Plugin::NS_CALENDARSERVER . '}share'] = 'Sabre\\CalDAV\\Xml\\Request\\Share'; |
| 96 | 96 | $this->server->xml->elementMap['{' . Plugin::NS_CALENDARSERVER . '}invite-reply'] = 'Sabre\\CalDAV\\Xml\\Request\\InviteReply'; |
| 97 | 97 | |
| 98 | - $this->server->on('propFind', [$this, 'propFindEarly']); |
|
| 99 | - $this->server->on('propFind', [$this, 'propFindLate'], 150); |
|
| 100 | - $this->server->on('propPatch', [$this, 'propPatch'], 40); |
|
| 101 | - $this->server->on('method:POST', [$this, 'httpPost']); |
|
| 98 | + $this->server->on('propFind', [$this, 'propFindEarly']); |
|
| 99 | + $this->server->on('propFind', [$this, 'propFindLate'], 150); |
|
| 100 | + $this->server->on('propPatch', [$this, 'propPatch'], 40); |
|
| 101 | + $this->server->on('method:POST', [$this, 'httpPost']); |
|
| 102 | 102 | |
| 103 | 103 | } |
| 104 | 104 | |
@@ -25,402 +25,402 @@ |
||
| 25 | 25 | */ |
| 26 | 26 | class SharingPlugin extends DAV\ServerPlugin { |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * These are the various status constants used by sharing-messages. |
|
| 30 | - */ |
|
| 31 | - const STATUS_ACCEPTED = 1; |
|
| 32 | - const STATUS_DECLINED = 2; |
|
| 33 | - const STATUS_DELETED = 3; |
|
| 34 | - const STATUS_NORESPONSE = 4; |
|
| 35 | - const STATUS_INVALID = 5; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Reference to SabreDAV server object. |
|
| 39 | - * |
|
| 40 | - * @var Sabre\DAV\Server |
|
| 41 | - */ |
|
| 42 | - protected $server; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * This method should return a list of server-features. |
|
| 46 | - * |
|
| 47 | - * This is for example 'versioning' and is added to the DAV: header |
|
| 48 | - * in an OPTIONS response. |
|
| 49 | - * |
|
| 50 | - * @return array |
|
| 51 | - */ |
|
| 52 | - public function getFeatures() { |
|
| 53 | - |
|
| 54 | - return ['calendarserver-sharing']; |
|
| 55 | - |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Returns a plugin name. |
|
| 60 | - * |
|
| 61 | - * Using this name other plugins will be able to access other plugins |
|
| 62 | - * using Sabre\DAV\Server::getPlugin |
|
| 63 | - * |
|
| 64 | - * @return string |
|
| 65 | - */ |
|
| 66 | - public function getPluginName() { |
|
| 67 | - |
|
| 68 | - return 'caldav-sharing'; |
|
| 69 | - |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * This initializes the plugin. |
|
| 74 | - * |
|
| 75 | - * This function is called by Sabre\DAV\Server, after |
|
| 76 | - * addPlugin is called. |
|
| 77 | - * |
|
| 78 | - * This method should set up the required event subscriptions. |
|
| 79 | - * |
|
| 80 | - * @param DAV\Server $server |
|
| 81 | - * @return void |
|
| 82 | - */ |
|
| 83 | - public function initialize(DAV\Server $server) { |
|
| 84 | - |
|
| 85 | - $this->server = $server; |
|
| 86 | - $server->resourceTypeMapping['Sabre\\CalDAV\\ISharedCalendar'] = '{' . Plugin::NS_CALENDARSERVER . '}shared'; |
|
| 87 | - |
|
| 88 | - array_push( |
|
| 89 | - $this->server->protectedProperties, |
|
| 90 | - '{' . Plugin::NS_CALENDARSERVER . '}invite', |
|
| 91 | - '{' . Plugin::NS_CALENDARSERVER . '}allowed-sharing-modes', |
|
| 92 | - '{' . Plugin::NS_CALENDARSERVER . '}shared-url' |
|
| 93 | - ); |
|
| 94 | - |
|
| 95 | - $this->server->xml->elementMap['{' . Plugin::NS_CALENDARSERVER . '}share'] = 'Sabre\\CalDAV\\Xml\\Request\\Share'; |
|
| 96 | - $this->server->xml->elementMap['{' . Plugin::NS_CALENDARSERVER . '}invite-reply'] = 'Sabre\\CalDAV\\Xml\\Request\\InviteReply'; |
|
| 97 | - |
|
| 98 | - $this->server->on('propFind', [$this, 'propFindEarly']); |
|
| 99 | - $this->server->on('propFind', [$this, 'propFindLate'], 150); |
|
| 100 | - $this->server->on('propPatch', [$this, 'propPatch'], 40); |
|
| 101 | - $this->server->on('method:POST', [$this, 'httpPost']); |
|
| 102 | - |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * This event is triggered when properties are requested for a certain |
|
| 107 | - * node. |
|
| 108 | - * |
|
| 109 | - * This allows us to inject any properties early. |
|
| 110 | - * |
|
| 111 | - * @param DAV\PropFind $propFind |
|
| 112 | - * @param DAV\INode $node |
|
| 113 | - * @return void |
|
| 114 | - */ |
|
| 115 | - public function propFindEarly(DAV\PropFind $propFind, DAV\INode $node) { |
|
| 116 | - |
|
| 117 | - if ($node instanceof IShareableCalendar) { |
|
| 118 | - |
|
| 119 | - $propFind->handle('{' . Plugin::NS_CALENDARSERVER . '}invite', function() use ($node) { |
|
| 120 | - return new Xml\Property\Invite( |
|
| 121 | - $node->getShares() |
|
| 122 | - ); |
|
| 123 | - }); |
|
| 124 | - |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - if ($node instanceof ISharedCalendar) { |
|
| 128 | - |
|
| 129 | - $propFind->handle('{' . Plugin::NS_CALENDARSERVER . '}shared-url', function() use ($node) { |
|
| 130 | - return new Href( |
|
| 131 | - $node->getSharedUrl() |
|
| 132 | - ); |
|
| 133 | - }); |
|
| 134 | - |
|
| 135 | - $propFind->handle('{' . Plugin::NS_CALENDARSERVER . '}invite', function() use ($node) { |
|
| 136 | - |
|
| 137 | - // Fetching owner information |
|
| 138 | - $props = $this->server->getPropertiesForPath($node->getOwner(), [ |
|
| 139 | - '{http://sabredav.org/ns}email-address', |
|
| 140 | - '{DAV:}displayname', |
|
| 141 | - ], 0); |
|
| 142 | - |
|
| 143 | - $ownerInfo = [ |
|
| 144 | - 'href' => $node->getOwner(), |
|
| 145 | - ]; |
|
| 146 | - |
|
| 147 | - if (isset($props[0][200])) { |
|
| 148 | - |
|
| 149 | - // We're mapping the internal webdav properties to the |
|
| 150 | - // elements caldav-sharing expects. |
|
| 151 | - if (isset($props[0][200]['{http://sabredav.org/ns}email-address'])) { |
|
| 152 | - $ownerInfo['href'] = 'mailto:' . $props[0][200]['{http://sabredav.org/ns}email-address']; |
|
| 153 | - } |
|
| 154 | - if (isset($props[0][200]['{DAV:}displayname'])) { |
|
| 155 | - $ownerInfo['commonName'] = $props[0][200]['{DAV:}displayname']; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - return new Xml\Property\Invite( |
|
| 161 | - $node->getShares(), |
|
| 162 | - $ownerInfo |
|
| 163 | - ); |
|
| 164 | - |
|
| 165 | - }); |
|
| 166 | - |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * This method is triggered *after* all properties have been retrieved. |
|
| 173 | - * This allows us to inject the correct resourcetype for calendars that |
|
| 174 | - * have been shared. |
|
| 175 | - * |
|
| 176 | - * @param DAV\PropFind $propFind |
|
| 177 | - * @param DAV\INode $node |
|
| 178 | - * @return void |
|
| 179 | - */ |
|
| 180 | - public function propFindLate(DAV\PropFind $propFind, DAV\INode $node) { |
|
| 181 | - |
|
| 182 | - if ($node instanceof IShareableCalendar) { |
|
| 183 | - if ($rt = $propFind->get('{DAV:}resourcetype')) { |
|
| 184 | - if (count($node->getShares()) > 0) { |
|
| 185 | - $rt->add('{' . Plugin::NS_CALENDARSERVER . '}shared-owner'); |
|
| 186 | - } |
|
| 187 | - } |
|
| 188 | - $propFind->handle('{' . Plugin::NS_CALENDARSERVER . '}allowed-sharing-modes', function() { |
|
| 189 | - return new Xml\Property\AllowedSharingModes(true, false); |
|
| 190 | - }); |
|
| 191 | - |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - /** |
|
| 197 | - * This method is trigged when a user attempts to update a node's |
|
| 198 | - * properties. |
|
| 199 | - * |
|
| 200 | - * A previous draft of the sharing spec stated that it was possible to use |
|
| 201 | - * PROPPATCH to remove 'shared-owner' from the resourcetype, thus unsharing |
|
| 202 | - * the calendar. |
|
| 203 | - * |
|
| 204 | - * Even though this is no longer in the current spec, we keep this around |
|
| 205 | - * because OS X 10.7 may still make use of this feature. |
|
| 206 | - * |
|
| 207 | - * @param string $path |
|
| 208 | - * @param DAV\PropPatch $propPatch |
|
| 209 | - * @return void |
|
| 210 | - */ |
|
| 211 | - public function propPatch($path, DAV\PropPatch $propPatch) { |
|
| 212 | - |
|
| 213 | - $node = $this->server->tree->getNodeForPath($path); |
|
| 214 | - if (!$node instanceof IShareableCalendar) |
|
| 215 | - return; |
|
| 216 | - |
|
| 217 | - $propPatch->handle('{DAV:}resourcetype', function($value) use ($node) { |
|
| 218 | - if ($value->is('{' . Plugin::NS_CALENDARSERVER . '}shared-owner')) return false; |
|
| 219 | - $shares = $node->getShares(); |
|
| 220 | - $remove = []; |
|
| 221 | - foreach ($shares as $share) { |
|
| 222 | - $remove[] = $share['href']; |
|
| 223 | - } |
|
| 224 | - $node->updateShares([], $remove); |
|
| 225 | - |
|
| 226 | - return true; |
|
| 227 | - |
|
| 228 | - }); |
|
| 229 | - |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - /** |
|
| 233 | - * We intercept this to handle POST requests on calendars. |
|
| 234 | - * |
|
| 235 | - * @param RequestInterface $request |
|
| 236 | - * @param ResponseInterface $response |
|
| 237 | - * @return null|bool |
|
| 238 | - */ |
|
| 239 | - public function httpPost(RequestInterface $request, ResponseInterface $response) { |
|
| 240 | - |
|
| 241 | - $path = $request->getPath(); |
|
| 242 | - |
|
| 243 | - // Only handling xml |
|
| 244 | - $contentType = $request->getHeader('Content-Type'); |
|
| 245 | - if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) |
|
| 246 | - return; |
|
| 247 | - |
|
| 248 | - // Making sure the node exists |
|
| 249 | - try { |
|
| 250 | - $node = $this->server->tree->getNodeForPath($path); |
|
| 251 | - } catch (DAV\Exception\NotFound $e) { |
|
| 252 | - return; |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - $requestBody = $request->getBodyAsString(); |
|
| 256 | - |
|
| 257 | - // If this request handler could not deal with this POST request, it |
|
| 258 | - // will return 'null' and other plugins get a chance to handle the |
|
| 259 | - // request. |
|
| 260 | - // |
|
| 261 | - // However, we already requested the full body. This is a problem, |
|
| 262 | - // because a body can only be read once. This is why we preemptively |
|
| 263 | - // re-populated the request body with the existing data. |
|
| 264 | - $request->setBody($requestBody); |
|
| 265 | - |
|
| 266 | - $message = $this->server->xml->parse($requestBody, $request->getUrl(), $documentType); |
|
| 267 | - |
|
| 268 | - switch ($documentType) { |
|
| 269 | - |
|
| 270 | - // Dealing with the 'share' document, which modified invitees on a |
|
| 271 | - // calendar. |
|
| 272 | - case '{' . Plugin::NS_CALENDARSERVER . '}share' : |
|
| 273 | - |
|
| 274 | - // We can only deal with IShareableCalendar objects |
|
| 275 | - if (!$node instanceof IShareableCalendar) { |
|
| 276 | - return; |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - $this->server->transactionType = 'post-calendar-share'; |
|
| 280 | - |
|
| 281 | - // Getting ACL info |
|
| 282 | - $acl = $this->server->getPlugin('acl'); |
|
| 283 | - |
|
| 284 | - // If there's no ACL support, we allow everything |
|
| 285 | - if ($acl) { |
|
| 286 | - $acl->checkPrivileges($path, '{DAV:}write'); |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - $node->updateShares($message->set, $message->remove); |
|
| 290 | - |
|
| 291 | - $response->setStatus(200); |
|
| 292 | - // Adding this because sending a response body may cause issues, |
|
| 293 | - // and I wanted some type of indicator the response was handled. |
|
| 294 | - $response->setHeader('X-Sabre-Status', 'everything-went-well'); |
|
| 295 | - |
|
| 296 | - // Breaking the event chain |
|
| 297 | - return false; |
|
| 298 | - |
|
| 299 | - // The invite-reply document is sent when the user replies to an |
|
| 300 | - // invitation of a calendar share. |
|
| 301 | - case '{' . Plugin::NS_CALENDARSERVER . '}invite-reply' : |
|
| 302 | - |
|
| 303 | - // This only works on the calendar-home-root node. |
|
| 304 | - if (!$node instanceof CalendarHome) { |
|
| 305 | - return; |
|
| 306 | - } |
|
| 307 | - $this->server->transactionType = 'post-invite-reply'; |
|
| 28 | + /** |
|
| 29 | + * These are the various status constants used by sharing-messages. |
|
| 30 | + */ |
|
| 31 | + const STATUS_ACCEPTED = 1; |
|
| 32 | + const STATUS_DECLINED = 2; |
|
| 33 | + const STATUS_DELETED = 3; |
|
| 34 | + const STATUS_NORESPONSE = 4; |
|
| 35 | + const STATUS_INVALID = 5; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Reference to SabreDAV server object. |
|
| 39 | + * |
|
| 40 | + * @var Sabre\DAV\Server |
|
| 41 | + */ |
|
| 42 | + protected $server; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * This method should return a list of server-features. |
|
| 46 | + * |
|
| 47 | + * This is for example 'versioning' and is added to the DAV: header |
|
| 48 | + * in an OPTIONS response. |
|
| 49 | + * |
|
| 50 | + * @return array |
|
| 51 | + */ |
|
| 52 | + public function getFeatures() { |
|
| 53 | + |
|
| 54 | + return ['calendarserver-sharing']; |
|
| 55 | + |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Returns a plugin name. |
|
| 60 | + * |
|
| 61 | + * Using this name other plugins will be able to access other plugins |
|
| 62 | + * using Sabre\DAV\Server::getPlugin |
|
| 63 | + * |
|
| 64 | + * @return string |
|
| 65 | + */ |
|
| 66 | + public function getPluginName() { |
|
| 67 | + |
|
| 68 | + return 'caldav-sharing'; |
|
| 69 | + |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * This initializes the plugin. |
|
| 74 | + * |
|
| 75 | + * This function is called by Sabre\DAV\Server, after |
|
| 76 | + * addPlugin is called. |
|
| 77 | + * |
|
| 78 | + * This method should set up the required event subscriptions. |
|
| 79 | + * |
|
| 80 | + * @param DAV\Server $server |
|
| 81 | + * @return void |
|
| 82 | + */ |
|
| 83 | + public function initialize(DAV\Server $server) { |
|
| 84 | + |
|
| 85 | + $this->server = $server; |
|
| 86 | + $server->resourceTypeMapping['Sabre\\CalDAV\\ISharedCalendar'] = '{' . Plugin::NS_CALENDARSERVER . '}shared'; |
|
| 87 | + |
|
| 88 | + array_push( |
|
| 89 | + $this->server->protectedProperties, |
|
| 90 | + '{' . Plugin::NS_CALENDARSERVER . '}invite', |
|
| 91 | + '{' . Plugin::NS_CALENDARSERVER . '}allowed-sharing-modes', |
|
| 92 | + '{' . Plugin::NS_CALENDARSERVER . '}shared-url' |
|
| 93 | + ); |
|
| 94 | + |
|
| 95 | + $this->server->xml->elementMap['{' . Plugin::NS_CALENDARSERVER . '}share'] = 'Sabre\\CalDAV\\Xml\\Request\\Share'; |
|
| 96 | + $this->server->xml->elementMap['{' . Plugin::NS_CALENDARSERVER . '}invite-reply'] = 'Sabre\\CalDAV\\Xml\\Request\\InviteReply'; |
|
| 97 | + |
|
| 98 | + $this->server->on('propFind', [$this, 'propFindEarly']); |
|
| 99 | + $this->server->on('propFind', [$this, 'propFindLate'], 150); |
|
| 100 | + $this->server->on('propPatch', [$this, 'propPatch'], 40); |
|
| 101 | + $this->server->on('method:POST', [$this, 'httpPost']); |
|
| 102 | + |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * This event is triggered when properties are requested for a certain |
|
| 107 | + * node. |
|
| 108 | + * |
|
| 109 | + * This allows us to inject any properties early. |
|
| 110 | + * |
|
| 111 | + * @param DAV\PropFind $propFind |
|
| 112 | + * @param DAV\INode $node |
|
| 113 | + * @return void |
|
| 114 | + */ |
|
| 115 | + public function propFindEarly(DAV\PropFind $propFind, DAV\INode $node) { |
|
| 116 | + |
|
| 117 | + if ($node instanceof IShareableCalendar) { |
|
| 118 | + |
|
| 119 | + $propFind->handle('{' . Plugin::NS_CALENDARSERVER . '}invite', function() use ($node) { |
|
| 120 | + return new Xml\Property\Invite( |
|
| 121 | + $node->getShares() |
|
| 122 | + ); |
|
| 123 | + }); |
|
| 124 | + |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + if ($node instanceof ISharedCalendar) { |
|
| 128 | + |
|
| 129 | + $propFind->handle('{' . Plugin::NS_CALENDARSERVER . '}shared-url', function() use ($node) { |
|
| 130 | + return new Href( |
|
| 131 | + $node->getSharedUrl() |
|
| 132 | + ); |
|
| 133 | + }); |
|
| 134 | + |
|
| 135 | + $propFind->handle('{' . Plugin::NS_CALENDARSERVER . '}invite', function() use ($node) { |
|
| 136 | + |
|
| 137 | + // Fetching owner information |
|
| 138 | + $props = $this->server->getPropertiesForPath($node->getOwner(), [ |
|
| 139 | + '{http://sabredav.org/ns}email-address', |
|
| 140 | + '{DAV:}displayname', |
|
| 141 | + ], 0); |
|
| 142 | + |
|
| 143 | + $ownerInfo = [ |
|
| 144 | + 'href' => $node->getOwner(), |
|
| 145 | + ]; |
|
| 146 | + |
|
| 147 | + if (isset($props[0][200])) { |
|
| 148 | + |
|
| 149 | + // We're mapping the internal webdav properties to the |
|
| 150 | + // elements caldav-sharing expects. |
|
| 151 | + if (isset($props[0][200]['{http://sabredav.org/ns}email-address'])) { |
|
| 152 | + $ownerInfo['href'] = 'mailto:' . $props[0][200]['{http://sabredav.org/ns}email-address']; |
|
| 153 | + } |
|
| 154 | + if (isset($props[0][200]['{DAV:}displayname'])) { |
|
| 155 | + $ownerInfo['commonName'] = $props[0][200]['{DAV:}displayname']; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + return new Xml\Property\Invite( |
|
| 161 | + $node->getShares(), |
|
| 162 | + $ownerInfo |
|
| 163 | + ); |
|
| 164 | + |
|
| 165 | + }); |
|
| 166 | + |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * This method is triggered *after* all properties have been retrieved. |
|
| 173 | + * This allows us to inject the correct resourcetype for calendars that |
|
| 174 | + * have been shared. |
|
| 175 | + * |
|
| 176 | + * @param DAV\PropFind $propFind |
|
| 177 | + * @param DAV\INode $node |
|
| 178 | + * @return void |
|
| 179 | + */ |
|
| 180 | + public function propFindLate(DAV\PropFind $propFind, DAV\INode $node) { |
|
| 181 | + |
|
| 182 | + if ($node instanceof IShareableCalendar) { |
|
| 183 | + if ($rt = $propFind->get('{DAV:}resourcetype')) { |
|
| 184 | + if (count($node->getShares()) > 0) { |
|
| 185 | + $rt->add('{' . Plugin::NS_CALENDARSERVER . '}shared-owner'); |
|
| 186 | + } |
|
| 187 | + } |
|
| 188 | + $propFind->handle('{' . Plugin::NS_CALENDARSERVER . '}allowed-sharing-modes', function() { |
|
| 189 | + return new Xml\Property\AllowedSharingModes(true, false); |
|
| 190 | + }); |
|
| 191 | + |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + /** |
|
| 197 | + * This method is trigged when a user attempts to update a node's |
|
| 198 | + * properties. |
|
| 199 | + * |
|
| 200 | + * A previous draft of the sharing spec stated that it was possible to use |
|
| 201 | + * PROPPATCH to remove 'shared-owner' from the resourcetype, thus unsharing |
|
| 202 | + * the calendar. |
|
| 203 | + * |
|
| 204 | + * Even though this is no longer in the current spec, we keep this around |
|
| 205 | + * because OS X 10.7 may still make use of this feature. |
|
| 206 | + * |
|
| 207 | + * @param string $path |
|
| 208 | + * @param DAV\PropPatch $propPatch |
|
| 209 | + * @return void |
|
| 210 | + */ |
|
| 211 | + public function propPatch($path, DAV\PropPatch $propPatch) { |
|
| 212 | + |
|
| 213 | + $node = $this->server->tree->getNodeForPath($path); |
|
| 214 | + if (!$node instanceof IShareableCalendar) |
|
| 215 | + return; |
|
| 216 | + |
|
| 217 | + $propPatch->handle('{DAV:}resourcetype', function($value) use ($node) { |
|
| 218 | + if ($value->is('{' . Plugin::NS_CALENDARSERVER . '}shared-owner')) return false; |
|
| 219 | + $shares = $node->getShares(); |
|
| 220 | + $remove = []; |
|
| 221 | + foreach ($shares as $share) { |
|
| 222 | + $remove[] = $share['href']; |
|
| 223 | + } |
|
| 224 | + $node->updateShares([], $remove); |
|
| 225 | + |
|
| 226 | + return true; |
|
| 227 | + |
|
| 228 | + }); |
|
| 229 | + |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + /** |
|
| 233 | + * We intercept this to handle POST requests on calendars. |
|
| 234 | + * |
|
| 235 | + * @param RequestInterface $request |
|
| 236 | + * @param ResponseInterface $response |
|
| 237 | + * @return null|bool |
|
| 238 | + */ |
|
| 239 | + public function httpPost(RequestInterface $request, ResponseInterface $response) { |
|
| 240 | + |
|
| 241 | + $path = $request->getPath(); |
|
| 242 | + |
|
| 243 | + // Only handling xml |
|
| 244 | + $contentType = $request->getHeader('Content-Type'); |
|
| 245 | + if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) |
|
| 246 | + return; |
|
| 247 | + |
|
| 248 | + // Making sure the node exists |
|
| 249 | + try { |
|
| 250 | + $node = $this->server->tree->getNodeForPath($path); |
|
| 251 | + } catch (DAV\Exception\NotFound $e) { |
|
| 252 | + return; |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + $requestBody = $request->getBodyAsString(); |
|
| 256 | + |
|
| 257 | + // If this request handler could not deal with this POST request, it |
|
| 258 | + // will return 'null' and other plugins get a chance to handle the |
|
| 259 | + // request. |
|
| 260 | + // |
|
| 261 | + // However, we already requested the full body. This is a problem, |
|
| 262 | + // because a body can only be read once. This is why we preemptively |
|
| 263 | + // re-populated the request body with the existing data. |
|
| 264 | + $request->setBody($requestBody); |
|
| 265 | + |
|
| 266 | + $message = $this->server->xml->parse($requestBody, $request->getUrl(), $documentType); |
|
| 267 | + |
|
| 268 | + switch ($documentType) { |
|
| 269 | + |
|
| 270 | + // Dealing with the 'share' document, which modified invitees on a |
|
| 271 | + // calendar. |
|
| 272 | + case '{' . Plugin::NS_CALENDARSERVER . '}share' : |
|
| 273 | + |
|
| 274 | + // We can only deal with IShareableCalendar objects |
|
| 275 | + if (!$node instanceof IShareableCalendar) { |
|
| 276 | + return; |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + $this->server->transactionType = 'post-calendar-share'; |
|
| 280 | + |
|
| 281 | + // Getting ACL info |
|
| 282 | + $acl = $this->server->getPlugin('acl'); |
|
| 283 | + |
|
| 284 | + // If there's no ACL support, we allow everything |
|
| 285 | + if ($acl) { |
|
| 286 | + $acl->checkPrivileges($path, '{DAV:}write'); |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + $node->updateShares($message->set, $message->remove); |
|
| 290 | + |
|
| 291 | + $response->setStatus(200); |
|
| 292 | + // Adding this because sending a response body may cause issues, |
|
| 293 | + // and I wanted some type of indicator the response was handled. |
|
| 294 | + $response->setHeader('X-Sabre-Status', 'everything-went-well'); |
|
| 295 | + |
|
| 296 | + // Breaking the event chain |
|
| 297 | + return false; |
|
| 298 | + |
|
| 299 | + // The invite-reply document is sent when the user replies to an |
|
| 300 | + // invitation of a calendar share. |
|
| 301 | + case '{' . Plugin::NS_CALENDARSERVER . '}invite-reply' : |
|
| 302 | + |
|
| 303 | + // This only works on the calendar-home-root node. |
|
| 304 | + if (!$node instanceof CalendarHome) { |
|
| 305 | + return; |
|
| 306 | + } |
|
| 307 | + $this->server->transactionType = 'post-invite-reply'; |
|
| 308 | 308 | |
| 309 | - // Getting ACL info |
|
| 310 | - $acl = $this->server->getPlugin('acl'); |
|
| 309 | + // Getting ACL info |
|
| 310 | + $acl = $this->server->getPlugin('acl'); |
|
| 311 | 311 | |
| 312 | - // If there's no ACL support, we allow everything |
|
| 313 | - if ($acl) { |
|
| 314 | - $acl->checkPrivileges($path, '{DAV:}write'); |
|
| 315 | - } |
|
| 312 | + // If there's no ACL support, we allow everything |
|
| 313 | + if ($acl) { |
|
| 314 | + $acl->checkPrivileges($path, '{DAV:}write'); |
|
| 315 | + } |
|
| 316 | 316 | |
| 317 | - $url = $node->shareReply( |
|
| 318 | - $message->href, |
|
| 319 | - $message->status, |
|
| 320 | - $message->calendarUri, |
|
| 321 | - $message->inReplyTo, |
|
| 322 | - $message->summary |
|
| 323 | - ); |
|
| 317 | + $url = $node->shareReply( |
|
| 318 | + $message->href, |
|
| 319 | + $message->status, |
|
| 320 | + $message->calendarUri, |
|
| 321 | + $message->inReplyTo, |
|
| 322 | + $message->summary |
|
| 323 | + ); |
|
| 324 | 324 | |
| 325 | - $response->setStatus(200); |
|
| 326 | - // Adding this because sending a response body may cause issues, |
|
| 327 | - // and I wanted some type of indicator the response was handled. |
|
| 328 | - $response->setHeader('X-Sabre-Status', 'everything-went-well'); |
|
| 325 | + $response->setStatus(200); |
|
| 326 | + // Adding this because sending a response body may cause issues, |
|
| 327 | + // and I wanted some type of indicator the response was handled. |
|
| 328 | + $response->setHeader('X-Sabre-Status', 'everything-went-well'); |
|
| 329 | 329 | |
| 330 | - if ($url) { |
|
| 331 | - $writer = $this->server->xml->getWriter($this->server->getBaseUri()); |
|
| 332 | - $writer->openMemory(); |
|
| 333 | - $writer->startDocument(); |
|
| 334 | - $writer->startElement('{' . Plugin::NS_CALENDARSERVER . '}shared-as'); |
|
| 335 | - $writer->write(new Href($url)); |
|
| 336 | - $writer->endElement(); |
|
| 337 | - $response->setHeader('Content-Type', 'application/xml'); |
|
| 338 | - $response->setBody($writer->outputMemory()); |
|
| 330 | + if ($url) { |
|
| 331 | + $writer = $this->server->xml->getWriter($this->server->getBaseUri()); |
|
| 332 | + $writer->openMemory(); |
|
| 333 | + $writer->startDocument(); |
|
| 334 | + $writer->startElement('{' . Plugin::NS_CALENDARSERVER . '}shared-as'); |
|
| 335 | + $writer->write(new Href($url)); |
|
| 336 | + $writer->endElement(); |
|
| 337 | + $response->setHeader('Content-Type', 'application/xml'); |
|
| 338 | + $response->setBody($writer->outputMemory()); |
|
| 339 | 339 | |
| 340 | - } |
|
| 340 | + } |
|
| 341 | 341 | |
| 342 | - // Breaking the event chain |
|
| 343 | - return false; |
|
| 342 | + // Breaking the event chain |
|
| 343 | + return false; |
|
| 344 | 344 | |
| 345 | - case '{' . Plugin::NS_CALENDARSERVER . '}publish-calendar' : |
|
| 345 | + case '{' . Plugin::NS_CALENDARSERVER . '}publish-calendar' : |
|
| 346 | 346 | |
| 347 | - // We can only deal with IShareableCalendar objects |
|
| 348 | - if (!$node instanceof IShareableCalendar) { |
|
| 349 | - return; |
|
| 350 | - } |
|
| 351 | - $this->server->transactionType = 'post-publish-calendar'; |
|
| 347 | + // We can only deal with IShareableCalendar objects |
|
| 348 | + if (!$node instanceof IShareableCalendar) { |
|
| 349 | + return; |
|
| 350 | + } |
|
| 351 | + $this->server->transactionType = 'post-publish-calendar'; |
|
| 352 | 352 | |
| 353 | - // Getting ACL info |
|
| 354 | - $acl = $this->server->getPlugin('acl'); |
|
| 353 | + // Getting ACL info |
|
| 354 | + $acl = $this->server->getPlugin('acl'); |
|
| 355 | 355 | |
| 356 | - // If there's no ACL support, we allow everything |
|
| 357 | - if ($acl) { |
|
| 358 | - $acl->checkPrivileges($path, '{DAV:}write'); |
|
| 359 | - } |
|
| 356 | + // If there's no ACL support, we allow everything |
|
| 357 | + if ($acl) { |
|
| 358 | + $acl->checkPrivileges($path, '{DAV:}write'); |
|
| 359 | + } |
|
| 360 | 360 | |
| 361 | - $node->setPublishStatus(true); |
|
| 361 | + $node->setPublishStatus(true); |
|
| 362 | 362 | |
| 363 | - // iCloud sends back the 202, so we will too. |
|
| 364 | - $response->setStatus(202); |
|
| 363 | + // iCloud sends back the 202, so we will too. |
|
| 364 | + $response->setStatus(202); |
|
| 365 | 365 | |
| 366 | - // Adding this because sending a response body may cause issues, |
|
| 367 | - // and I wanted some type of indicator the response was handled. |
|
| 368 | - $response->setHeader('X-Sabre-Status', 'everything-went-well'); |
|
| 366 | + // Adding this because sending a response body may cause issues, |
|
| 367 | + // and I wanted some type of indicator the response was handled. |
|
| 368 | + $response->setHeader('X-Sabre-Status', 'everything-went-well'); |
|
| 369 | 369 | |
| 370 | - // Breaking the event chain |
|
| 371 | - return false; |
|
| 370 | + // Breaking the event chain |
|
| 371 | + return false; |
|
| 372 | 372 | |
| 373 | - case '{' . Plugin::NS_CALENDARSERVER . '}unpublish-calendar' : |
|
| 373 | + case '{' . Plugin::NS_CALENDARSERVER . '}unpublish-calendar' : |
|
| 374 | 374 | |
| 375 | - // We can only deal with IShareableCalendar objects |
|
| 376 | - if (!$node instanceof IShareableCalendar) { |
|
| 377 | - return; |
|
| 378 | - } |
|
| 379 | - $this->server->transactionType = 'post-unpublish-calendar'; |
|
| 375 | + // We can only deal with IShareableCalendar objects |
|
| 376 | + if (!$node instanceof IShareableCalendar) { |
|
| 377 | + return; |
|
| 378 | + } |
|
| 379 | + $this->server->transactionType = 'post-unpublish-calendar'; |
|
| 380 | 380 | |
| 381 | - // Getting ACL info |
|
| 382 | - $acl = $this->server->getPlugin('acl'); |
|
| 381 | + // Getting ACL info |
|
| 382 | + $acl = $this->server->getPlugin('acl'); |
|
| 383 | 383 | |
| 384 | - // If there's no ACL support, we allow everything |
|
| 385 | - if ($acl) { |
|
| 386 | - $acl->checkPrivileges($path, '{DAV:}write'); |
|
| 387 | - } |
|
| 384 | + // If there's no ACL support, we allow everything |
|
| 385 | + if ($acl) { |
|
| 386 | + $acl->checkPrivileges($path, '{DAV:}write'); |
|
| 387 | + } |
|
| 388 | 388 | |
| 389 | - $node->setPublishStatus(false); |
|
| 389 | + $node->setPublishStatus(false); |
|
| 390 | 390 | |
| 391 | - $response->setStatus(200); |
|
| 391 | + $response->setStatus(200); |
|
| 392 | 392 | |
| 393 | - // Adding this because sending a response body may cause issues, |
|
| 394 | - // and I wanted some type of indicator the response was handled. |
|
| 395 | - $response->setHeader('X-Sabre-Status', 'everything-went-well'); |
|
| 393 | + // Adding this because sending a response body may cause issues, |
|
| 394 | + // and I wanted some type of indicator the response was handled. |
|
| 395 | + $response->setHeader('X-Sabre-Status', 'everything-went-well'); |
|
| 396 | 396 | |
| 397 | - // Breaking the event chain |
|
| 398 | - return false; |
|
| 397 | + // Breaking the event chain |
|
| 398 | + return false; |
|
| 399 | 399 | |
| 400 | - } |
|
| 400 | + } |
|
| 401 | 401 | |
| 402 | 402 | |
| 403 | 403 | |
| 404 | - } |
|
| 404 | + } |
|
| 405 | 405 | |
| 406 | - /** |
|
| 407 | - * Returns a bunch of meta-data about the plugin. |
|
| 408 | - * |
|
| 409 | - * Providing this information is optional, and is mainly displayed by the |
|
| 410 | - * Browser plugin. |
|
| 411 | - * |
|
| 412 | - * The description key in the returned array may contain html and will not |
|
| 413 | - * be sanitized. |
|
| 414 | - * |
|
| 415 | - * @return array |
|
| 416 | - */ |
|
| 417 | - public function getPluginInfo() { |
|
| 406 | + /** |
|
| 407 | + * Returns a bunch of meta-data about the plugin. |
|
| 408 | + * |
|
| 409 | + * Providing this information is optional, and is mainly displayed by the |
|
| 410 | + * Browser plugin. |
|
| 411 | + * |
|
| 412 | + * The description key in the returned array may contain html and will not |
|
| 413 | + * be sanitized. |
|
| 414 | + * |
|
| 415 | + * @return array |
|
| 416 | + */ |
|
| 417 | + public function getPluginInfo() { |
|
| 418 | 418 | |
| 419 | - return [ |
|
| 420 | - 'name' => $this->getPluginName(), |
|
| 421 | - 'description' => 'Adds support for caldav-sharing.', |
|
| 422 | - 'link' => 'http://sabre.io/dav/caldav-sharing/', |
|
| 423 | - ]; |
|
| 419 | + return [ |
|
| 420 | + 'name' => $this->getPluginName(), |
|
| 421 | + 'description' => 'Adds support for caldav-sharing.', |
|
| 422 | + 'link' => 'http://sabre.io/dav/caldav-sharing/', |
|
| 423 | + ]; |
|
| 424 | 424 | |
| 425 | - } |
|
| 425 | + } |
|
| 426 | 426 | } |
@@ -211,11 +211,14 @@ discard block |
||
| 211 | 211 | public function propPatch($path, DAV\PropPatch $propPatch) { |
| 212 | 212 | |
| 213 | 213 | $node = $this->server->tree->getNodeForPath($path); |
| 214 | - if (!$node instanceof IShareableCalendar) |
|
| 215 | - return; |
|
| 214 | + if (!$node instanceof IShareableCalendar) { |
|
| 215 | + return; |
|
| 216 | + } |
|
| 216 | 217 | |
| 217 | 218 | $propPatch->handle('{DAV:}resourcetype', function($value) use ($node) { |
| 218 | - if ($value->is('{' . Plugin::NS_CALENDARSERVER . '}shared-owner')) return false; |
|
| 219 | + if ($value->is('{' . Plugin::NS_CALENDARSERVER . '}shared-owner')) { |
|
| 220 | + return false; |
|
| 221 | + } |
|
| 219 | 222 | $shares = $node->getShares(); |
| 220 | 223 | $remove = []; |
| 221 | 224 | foreach ($shares as $share) { |
@@ -242,8 +245,9 @@ discard block |
||
| 242 | 245 | |
| 243 | 246 | // Only handling xml |
| 244 | 247 | $contentType = $request->getHeader('Content-Type'); |
| 245 | - if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) |
|
| 246 | - return; |
|
| 248 | + if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) { |
|
| 249 | + return; |
|
| 250 | + } |
|
| 247 | 251 | |
| 248 | 252 | // Making sure the node exists |
| 249 | 253 | try { |