1
|
|
|
<?php namespace CalDAVClient\Facade\Responses; |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2017 OpenStack Foundation |
5
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
6
|
|
|
* you may not use this file except in compliance with the License. |
7
|
|
|
* You may obtain a copy of the License at |
8
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
9
|
|
|
* Unless required by applicable law or agreed to in writing, software |
10
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
11
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12
|
|
|
* See the License for the specific language governing permissions and |
13
|
|
|
* limitations under the License. |
14
|
|
|
**/ |
15
|
|
|
|
16
|
|
|
use CalDAVClient\Facade\Exceptions\ForbiddenQueryException; |
17
|
|
|
use CalDAVClient\Facade\Exceptions\NotValidGenericSingleCalDAVResponseException; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class GenericSinglePROPFINDCalDAVResponse |
21
|
|
|
* @package CalDAVClient\Facade\Responses |
22
|
|
|
* @see https://tools.ietf.org/html/rfc2518#section-11 |
23
|
|
|
*/ |
24
|
|
|
class GenericSinglePROPFINDCalDAVResponse extends AbstractCalDAVResponse |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var array |
28
|
|
|
*/ |
29
|
|
|
protected $found_props = []; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var array |
33
|
|
|
*/ |
34
|
|
|
protected $not_found_props = []; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @return $this |
38
|
|
|
* @throws ForbiddenQueryException |
39
|
|
|
* @throw NotValidGenericSingleCalDAVResponseException |
40
|
|
|
*/ |
41
|
|
|
protected function parse() |
42
|
|
|
{ |
43
|
|
|
|
44
|
|
|
if (!$this->isValid()) throw new NotValidGenericSingleCalDAVResponseException(); |
45
|
|
|
if (!isset($this->content['response']['propstat'])) return $this; |
46
|
|
|
if (isset($this->content['response']['propstat']['prop']) && isset($this->content['response']['propstat']['status'])) { |
47
|
|
|
// all props found |
48
|
|
|
$status = $this->content['response']['propstat']['status']; |
49
|
|
|
if ($this->statusMatches($status, AbstractCalDAVResponse::HttpOKStatus)) { |
50
|
|
|
$this->found_props = $this->content['response']['propstat']['prop']; |
51
|
|
|
$this->not_found_props = null; |
52
|
|
|
} |
53
|
|
|
if ($this->statusMatches($status, AbstractCalDAVResponse::HttpNotFoundStatus)) { |
54
|
|
|
$this->not_found_props = $this->content['response']['propstat']['prop']; |
55
|
|
|
$this->found_props = null; |
56
|
|
|
} |
57
|
|
|
if ($this->statusMatches($status, AbstractCalDAVResponse::HttpForbiddenStatus)) { |
58
|
|
|
throw new ForbiddenQueryException(); |
59
|
|
|
} |
60
|
|
|
return $this; |
61
|
|
|
} |
62
|
|
|
// multi props ( found or not found) |
63
|
|
|
foreach ($this->content['response']['propstat'] as $propstat) { |
64
|
|
|
|
65
|
|
|
if (!isset($propstat['status']) || !isset($propstat['prop'])) continue; |
66
|
|
|
|
67
|
|
|
if ($this->statusMatches($propstat['status'], AbstractCalDAVResponse::HttpOKStatus)) |
68
|
|
|
$this->found_props = $propstat['prop']; |
69
|
|
|
|
70
|
|
|
if ($this->statusMatches($propstat['status'], AbstractCalDAVResponse::HttpNotFoundStatus)) |
71
|
|
|
$this->not_found_props = $propstat['prop']; |
72
|
|
|
} |
73
|
|
|
return $this; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @param string $responseStatus |
78
|
|
|
* @param string $desiredStatus |
79
|
|
|
* @return bool |
80
|
|
|
*/ |
81
|
|
|
protected function statusMatches($responseStatus, $desiredStatus) |
82
|
|
|
{ |
83
|
|
|
return strtoupper($responseStatus) == $desiredStatus; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @return bool |
88
|
|
|
*/ |
89
|
|
|
protected function isValid() |
90
|
|
|
{ |
91
|
|
|
return parent::isValid() ; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @return string|null |
96
|
|
|
*/ |
97
|
|
|
public function getHRef() |
98
|
|
|
{ |
99
|
|
|
return isset($this->content['response']['href']) ? $this->content['response']['href'] : null; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @return bool |
104
|
|
|
*/ |
105
|
|
|
public function isSuccessFull() |
106
|
|
|
{ |
107
|
|
|
return $this->code == HttpResponse::HttpCodeMultiResponse; |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|