@@ -21,7 +21,7 @@ |
||
21 | 21 | /** |
22 | 22 | * @return bool |
23 | 23 | */ |
24 | - public function isSuccessFull(){ |
|
24 | + public function isSuccessFull() { |
|
25 | 25 | return $this->code == HttpResponse::HttpCodeNoContent; |
26 | 26 | } |
27 | 27 | } |
28 | 28 | \ No newline at end of file |
@@ -26,8 +26,8 @@ discard block |
||
26 | 26 | * @param array $params |
27 | 27 | * @return array |
28 | 28 | */ |
29 | - private static function createHeadersFor($http_method, array $params = []){ |
|
30 | - switch ($http_method){ |
|
29 | + private static function createHeadersFor($http_method, array $params = []) { |
|
30 | + switch ($http_method) { |
|
31 | 31 | case HttpMethods::PropFind: |
32 | 32 | case HttpMethods::Options: |
33 | 33 | case HttpMethods::Report: |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | break; |
40 | 40 | case HttpMethods::Delete: |
41 | 41 | $etag = $params[0]; |
42 | - if(!empty($etag)) |
|
42 | + if (!empty($etag)) |
|
43 | 43 | return [ |
44 | 44 | Headers::IfMatch => $params[0], |
45 | 45 | ]; |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | break; |
54 | 54 | case HttpMethods::Put: |
55 | 55 | $etag = $params[0]; |
56 | - if(empty($etag)){ |
|
56 | + if (empty($etag)) { |
|
57 | 57 | return [ |
58 | 58 | Headers::ContentType => ContentTypes::Calendar, |
59 | 59 | Headers::IfNotMatch => '*', |
@@ -73,11 +73,10 @@ discard block |
||
73 | 73 | * @param int $depth |
74 | 74 | * @return Request |
75 | 75 | */ |
76 | - public static function createPropFindRequest($url , $body, $depth = 1){ |
|
77 | - return new Request |
|
78 | - ( |
|
76 | + public static function createPropFindRequest($url, $body, $depth = 1) { |
|
77 | + return new Request( |
|
79 | 78 | HttpMethods::PropFind, |
80 | - $url , |
|
79 | + $url, |
|
81 | 80 | self::createHeadersFor(HttpMethods::PropFind, [$depth]), |
82 | 81 | $body |
83 | 82 | ); |
@@ -88,9 +87,8 @@ discard block |
||
88 | 87 | * @param string $body |
89 | 88 | * @return Request |
90 | 89 | */ |
91 | - public static function createMakeCalendarRequest($url , $body){ |
|
92 | - return new Request |
|
93 | - ( |
|
90 | + public static function createMakeCalendarRequest($url, $body) { |
|
91 | + return new Request( |
|
94 | 92 | HttpMethods::MakeCalendar, |
95 | 93 | $url, |
96 | 94 | self::createHeadersFor(HttpMethods::MakeCalendar), |
@@ -103,9 +101,8 @@ discard block |
||
103 | 101 | * @param int $depth |
104 | 102 | * @return Request |
105 | 103 | */ |
106 | - public static function createOptionsRequest($url, $depth = 1){ |
|
107 | - return new Request |
|
108 | - ( |
|
104 | + public static function createOptionsRequest($url, $depth = 1) { |
|
105 | + return new Request( |
|
109 | 106 | HttpMethods::Options, |
110 | 107 | $url, |
111 | 108 | self::createHeadersFor(HttpMethods::Options, [$depth]) |
@@ -118,9 +115,8 @@ discard block |
||
118 | 115 | * @param int $depth |
119 | 116 | * @return Request |
120 | 117 | */ |
121 | - public static function createReportRequest($url , $body, $depth = 1){ |
|
122 | - return new Request |
|
123 | - ( |
|
118 | + public static function createReportRequest($url, $body, $depth = 1) { |
|
119 | + return new Request( |
|
124 | 120 | HttpMethods::Report, |
125 | 121 | $url, |
126 | 122 | self::createHeadersFor(HttpMethods::Report, [$depth]), |
@@ -133,9 +129,8 @@ discard block |
||
133 | 129 | * @param string $etag |
134 | 130 | * @return Request |
135 | 131 | */ |
136 | - public static function createDeleteRequest($url , $etag){ |
|
137 | - return new Request |
|
138 | - ( |
|
132 | + public static function createDeleteRequest($url, $etag) { |
|
133 | + return new Request( |
|
139 | 134 | HttpMethods::Delete, |
140 | 135 | $url, |
141 | 136 | self::createHeadersFor(HttpMethods::Delete, [$etag]) |
@@ -146,9 +141,8 @@ discard block |
||
146 | 141 | * @param string $url |
147 | 142 | * @return Request |
148 | 143 | */ |
149 | - public static function createGetRequest($url){ |
|
150 | - return new Request |
|
151 | - ( |
|
144 | + public static function createGetRequest($url) { |
|
145 | + return new Request( |
|
152 | 146 | HttpMethods::Get, |
153 | 147 | $url, |
154 | 148 | self::createHeadersFor(HttpMethods::Get) |
@@ -161,9 +155,8 @@ discard block |
||
161 | 155 | * @param string $etag |
162 | 156 | * @return Request |
163 | 157 | */ |
164 | - public static function createPutRequest($url, $body, $etag = null){ |
|
165 | - return new Request |
|
166 | - ( |
|
158 | + public static function createPutRequest($url, $body, $etag = null) { |
|
159 | + return new Request( |
|
167 | 160 | HttpMethods::Put, |
168 | 161 | $url, |
169 | 162 | self::createHeadersFor(HttpMethods::Put, [$etag]), |
@@ -39,10 +39,11 @@ |
||
39 | 39 | break; |
40 | 40 | case HttpMethods::Delete: |
41 | 41 | $etag = $params[0]; |
42 | - if(!empty($etag)) |
|
43 | - return [ |
|
42 | + if(!empty($etag)) { |
|
43 | + return [ |
|
44 | 44 | Headers::IfMatch => $params[0], |
45 | 45 | ]; |
46 | + } |
|
46 | 47 | return []; |
47 | 48 | break; |
48 | 49 | case HttpMethods::MakeCalendar: |
@@ -125,15 +125,15 @@ discard block |
||
125 | 125 | * @param Request $http_request |
126 | 126 | * @return mixed|\Psr\Http\Message\ResponseInterface |
127 | 127 | */ |
128 | - private function makeRequest(Request $http_request){ |
|
129 | - try{ |
|
128 | + private function makeRequest(Request $http_request) { |
|
129 | + try { |
|
130 | 130 | return $this->client->send($http_request, [ |
131 | 131 | 'auth' => [$this->user, $this->password], |
132 | 132 | 'timeout' => $this->timeout |
133 | 133 | ]); |
134 | 134 | } |
135 | - catch (ClientException $ex){ |
|
136 | - switch($ex->getCode()){ |
|
135 | + catch (ClientException $ex) { |
|
136 | + switch ($ex->getCode()) { |
|
137 | 137 | case 401: |
138 | 138 | throw new UserUnAuthorizedException(); |
139 | 139 | break; |
@@ -161,9 +161,9 @@ discard block |
||
161 | 161 | |
162 | 162 | $res = $http_response->hasHeader(self::DAVHeader); |
163 | 163 | $options = []; |
164 | - if($res){ |
|
164 | + if ($res) { |
|
165 | 165 | $val = $http_response->getHeaderLine(self::DAVHeader); |
166 | - if(!empty($val)){ |
|
166 | + if (!empty($val)) { |
|
167 | 167 | $options = explode(', ', $val); |
168 | 168 | } |
169 | 169 | } |
@@ -177,14 +177,13 @@ discard block |
||
177 | 177 | public function getUserPrincipal() |
178 | 178 | { |
179 | 179 | $http_response = $this->makeRequest( |
180 | - RequestFactory::createPropFindRequest |
|
181 | - ( |
|
180 | + RequestFactory::createPropFindRequest( |
|
182 | 181 | $this->server_url, |
183 | 182 | CalDAVRequestFactory::getInstance()->build(CalDAVRequestFactory::PrincipalRequestType)->getContent() |
184 | 183 | ) |
185 | 184 | ); |
186 | 185 | |
187 | - return new UserPrincipalResponse($this->server_url, (string)$http_response->getBody(), $http_response->getStatusCode()); |
|
186 | + return new UserPrincipalResponse($this->server_url, (string) $http_response->getBody(), $http_response->getStatusCode()); |
|
188 | 187 | } |
189 | 188 | |
190 | 189 | /** |
@@ -194,14 +193,13 @@ discard block |
||
194 | 193 | public function getCalendarHome($principal_url) |
195 | 194 | { |
196 | 195 | $http_response = $this->makeRequest( |
197 | - RequestFactory::createPropFindRequest |
|
198 | - ( |
|
196 | + RequestFactory::createPropFindRequest( |
|
199 | 197 | $principal_url, |
200 | 198 | CalDAVRequestFactory::getInstance()->build(CalDAVRequestFactory::CalendarHomeRequestType)->getContent() |
201 | 199 | ) |
202 | 200 | ); |
203 | 201 | |
204 | - return new CalendarHomesResponse($this->server_url, (string)$http_response->getBody(), $http_response->getStatusCode()); |
|
202 | + return new CalendarHomesResponse($this->server_url, (string) $http_response->getBody(), $http_response->getStatusCode()); |
|
205 | 203 | } |
206 | 204 | |
207 | 205 | /** |
@@ -213,8 +211,7 @@ discard block |
||
213 | 211 | public function createCalendar($calendar_home_set, MakeCalendarRequestVO $vo) |
214 | 212 | { |
215 | 213 | $http_response = $this->makeRequest( |
216 | - RequestFactory::createMakeCalendarRequest |
|
217 | - ( |
|
214 | + RequestFactory::createMakeCalendarRequest( |
|
218 | 215 | $calendar_home_set.$vo->getResourceName(), |
219 | 216 | CalDAVRequestFactory::getInstance()->build(CalDAVRequestFactory::CalendarCreateRequestType, [$vo])->getContent() |
220 | 217 | ) |
@@ -230,14 +227,13 @@ discard block |
||
230 | 227 | public function getCalendars($calendar_home_set_url) |
231 | 228 | { |
232 | 229 | $http_response = $this->makeRequest( |
233 | - RequestFactory::createPropFindRequest |
|
234 | - ( |
|
230 | + RequestFactory::createPropFindRequest( |
|
235 | 231 | $calendar_home_set_url, |
236 | 232 | CalDAVRequestFactory::getInstance()->build(CalDAVRequestFactory::CalendarsRequestType)->getContent() |
237 | 233 | ) |
238 | 234 | ); |
239 | 235 | |
240 | - return new GetCalendarsResponse($this->server_url, (string)$http_response->getBody(), $http_response->getStatusCode()); |
|
236 | + return new GetCalendarsResponse($this->server_url, (string) $http_response->getBody(), $http_response->getStatusCode()); |
|
241 | 237 | } |
242 | 238 | |
243 | 239 | /** |
@@ -247,15 +243,14 @@ discard block |
||
247 | 243 | public function getCalendar($calendar_url) |
248 | 244 | { |
249 | 245 | $http_response = $this->makeRequest( |
250 | - RequestFactory::createPropFindRequest |
|
251 | - ( |
|
246 | + RequestFactory::createPropFindRequest( |
|
252 | 247 | $calendar_url, |
253 | 248 | CalDAVRequestFactory::getInstance()->build(CalDAVRequestFactory::CalendarRequestType)->getContent(), |
254 | 249 | 0 |
255 | 250 | ) |
256 | 251 | ); |
257 | 252 | |
258 | - return new GetCalendarResponse($this->server_url, (string)$http_response->getBody(), $http_response->getStatusCode()); |
|
253 | + return new GetCalendarResponse($this->server_url, (string) $http_response->getBody(), $http_response->getStatusCode()); |
|
259 | 254 | } |
260 | 255 | |
261 | 256 | |
@@ -268,14 +263,13 @@ discard block |
||
268 | 263 | { |
269 | 264 | |
270 | 265 | $http_response = $this->makeRequest( |
271 | - RequestFactory::createReportRequest |
|
272 | - ( |
|
266 | + RequestFactory::createReportRequest( |
|
273 | 267 | $calendar_url, |
274 | 268 | CalDAVRequestFactory::getInstance()->build(CalDAVRequestFactory::CalendarSyncRequestType, [$sync_token])->getContent() |
275 | 269 | ) |
276 | 270 | ); |
277 | 271 | |
278 | - return new CalendarSyncInfoResponse($this->server_url, (string)$http_response->getBody(), $http_response->getStatusCode()); |
|
272 | + return new CalendarSyncInfoResponse($this->server_url, (string) $http_response->getBody(), $http_response->getStatusCode()); |
|
279 | 273 | } |
280 | 274 | |
281 | 275 | /** |
@@ -288,19 +282,17 @@ discard block |
||
288 | 282 | $uid = $vo->getUID(); |
289 | 283 | $resource_url = $calendar_url.$uid.self::SchedulingInformationSuffix; |
290 | 284 | $http_response = $this->makeRequest( |
291 | - RequestFactory::createPutRequest |
|
292 | - ( |
|
285 | + RequestFactory::createPutRequest( |
|
293 | 286 | $resource_url, |
294 | 287 | CalDAVRequestFactory::getInstance()->build(CalDAVRequestFactory::EventCreateRequestType, [$vo])->getContent() |
295 | 288 | ) |
296 | 289 | ); |
297 | 290 | $etag = $http_response->hasHeader(self::ETagHeader) ? $http_response->getHeaderLine(self::ETagHeader) : null; |
298 | - return new EventCreatedResponse |
|
299 | - ( |
|
291 | + return new EventCreatedResponse( |
|
300 | 292 | $uid, |
301 | 293 | $etag, |
302 | 294 | $resource_url, |
303 | - (string)$http_response->getBody(), |
|
295 | + (string) $http_response->getBody(), |
|
304 | 296 | $http_response->getStatusCode() |
305 | 297 | ); |
306 | 298 | } |
@@ -316,20 +308,18 @@ discard block |
||
316 | 308 | $uid = $vo->getUID(); |
317 | 309 | $resource_url = $calendar_url.$uid.self::SchedulingInformationSuffix; |
318 | 310 | $http_response = $this->makeRequest( |
319 | - RequestFactory::createPutRequest |
|
320 | - ( |
|
311 | + RequestFactory::createPutRequest( |
|
321 | 312 | $resource_url, |
322 | 313 | CalDAVRequestFactory::getInstance()->build(CalDAVRequestFactory::EventUpdateRequestType, [$vo])->getContent(), |
323 | 314 | $etag |
324 | 315 | ) |
325 | 316 | ); |
326 | 317 | $etag = $http_response->hasHeader(self::ETagHeader) ? $http_response->getHeaderLine(self::ETagHeader) : null; |
327 | - return new EventUpdatedResponse |
|
328 | - ( |
|
318 | + return new EventUpdatedResponse( |
|
329 | 319 | $uid, |
330 | 320 | $etag, |
331 | 321 | $resource_url, |
332 | - (string)$http_response->getBody(), |
|
322 | + (string) $http_response->getBody(), |
|
333 | 323 | $http_response->getStatusCode() |
334 | 324 | ); |
335 | 325 | } |
@@ -343,16 +333,14 @@ discard block |
||
343 | 333 | public function deleteEvent($calendar_url, $uid, $etag) |
344 | 334 | { |
345 | 335 | $http_response = $this->makeRequest( |
346 | - RequestFactory::createDeleteRequest |
|
347 | - ( |
|
336 | + RequestFactory::createDeleteRequest( |
|
348 | 337 | $calendar_url.$uid.self::SchedulingInformationSuffix, |
349 | 338 | $etag |
350 | 339 | ) |
351 | 340 | ); |
352 | 341 | |
353 | - return new EventDeletedResponse |
|
354 | - ( |
|
355 | - $this->server_url, (string)$http_response->getBody(), $http_response->getStatusCode() |
|
342 | + return new EventDeletedResponse( |
|
343 | + $this->server_url, (string) $http_response->getBody(), $http_response->getStatusCode() |
|
356 | 344 | ); |
357 | 345 | } |
358 | 346 | |
@@ -360,15 +348,14 @@ discard block |
||
360 | 348 | * @param string $event_url |
361 | 349 | * @return string |
362 | 350 | */ |
363 | - public function getEventVCardBy($event_url){ |
|
351 | + public function getEventVCardBy($event_url) { |
|
364 | 352 | $http_response = $this->makeRequest( |
365 | - RequestFactory::createGetRequest |
|
366 | - ( |
|
353 | + RequestFactory::createGetRequest( |
|
367 | 354 | $event_url |
368 | 355 | ) |
369 | 356 | ); |
370 | 357 | |
371 | - $ical = (string)$http_response->getBody(); |
|
358 | + $ical = (string) $http_response->getBody(); |
|
372 | 359 | return $ical; |
373 | 360 | } |
374 | 361 | |
@@ -380,17 +367,15 @@ discard block |
||
380 | 367 | public function getEventsBy($calendar_url, array $events_urls) |
381 | 368 | { |
382 | 369 | $http_response = $this->makeRequest( |
383 | - RequestFactory::createReportRequest |
|
384 | - ( |
|
370 | + RequestFactory::createReportRequest( |
|
385 | 371 | $calendar_url, |
386 | 372 | CalDAVRequestFactory::getInstance()->build(CalDAVRequestFactory::CalendarMultiGetRequestType, [$events_urls])->getContent() |
387 | 373 | ) |
388 | 374 | ); |
389 | 375 | |
390 | - return new ResourceCollectionResponse |
|
391 | - ( |
|
376 | + return new ResourceCollectionResponse( |
|
392 | 377 | $this->server_url, |
393 | - (string)$http_response->getBody(), |
|
378 | + (string) $http_response->getBody(), |
|
394 | 379 | $http_response->getStatusCode() |
395 | 380 | ); |
396 | 381 | } |
@@ -404,17 +389,15 @@ discard block |
||
404 | 389 | { |
405 | 390 | |
406 | 391 | $http_response = $this->makeRequest( |
407 | - RequestFactory::createReportRequest |
|
408 | - ( |
|
392 | + RequestFactory::createReportRequest( |
|
409 | 393 | $calendar_url, |
410 | 394 | CalDAVRequestFactory::getInstance()->build(CalDAVRequestFactory::CalendarQueryRequestType, [$filter])->getContent() |
411 | 395 | ) |
412 | 396 | ); |
413 | 397 | |
414 | - return new ResourceCollectionResponse |
|
415 | - ( |
|
398 | + return new ResourceCollectionResponse( |
|
416 | 399 | $this->server_url, |
417 | - (string)$http_response->getBody(), |
|
400 | + (string) $http_response->getBody(), |
|
418 | 401 | $http_response->getStatusCode() |
419 | 402 | ); |
420 | 403 | } |
@@ -427,16 +410,14 @@ discard block |
||
427 | 410 | public function deleteCalendar($calendar_url, $etag = null) |
428 | 411 | { |
429 | 412 | $http_response = $this->makeRequest( |
430 | - RequestFactory::createDeleteRequest |
|
431 | - ( |
|
413 | + RequestFactory::createDeleteRequest( |
|
432 | 414 | $calendar_url, |
433 | 415 | $etag |
434 | 416 | ) |
435 | 417 | ); |
436 | 418 | |
437 | - return new CalendarDeletedResponse |
|
438 | - ( |
|
439 | - $this->server_url, (string)$http_response->getBody(), $http_response->getStatusCode() |
|
419 | + return new CalendarDeletedResponse( |
|
420 | + $this->server_url, (string) $http_response->getBody(), $http_response->getStatusCode() |
|
440 | 421 | ); |
441 | 422 | } |
442 | 423 | } |
443 | 424 | \ No newline at end of file |