@@ -124,15 +124,15 @@ discard block |
||
| 124 | 124 | * @param Request $http_request |
| 125 | 125 | * @return mixed|\Psr\Http\Message\ResponseInterface |
| 126 | 126 | */ |
| 127 | - private function makeRequest(Request $http_request){ |
|
| 128 | - try{ |
|
| 127 | + private function makeRequest(Request $http_request) { |
|
| 128 | + try { |
|
| 129 | 129 | return $this->client->send($http_request, [ |
| 130 | 130 | 'auth' => [$this->user, $this->password], |
| 131 | 131 | 'timeout' => $this->timeout |
| 132 | 132 | ]); |
| 133 | 133 | } |
| 134 | - catch (ClientException $ex){ |
|
| 135 | - switch($ex->getCode()){ |
|
| 134 | + catch (ClientException $ex) { |
|
| 135 | + switch ($ex->getCode()) { |
|
| 136 | 136 | case 401: |
| 137 | 137 | throw new UserUnAuthorizedException(); |
| 138 | 138 | break; |
@@ -160,9 +160,9 @@ discard block |
||
| 160 | 160 | |
| 161 | 161 | $res = $http_response->hasHeader(self::DAVHeader); |
| 162 | 162 | $options = []; |
| 163 | - if($res){ |
|
| 163 | + if ($res) { |
|
| 164 | 164 | $val = $http_response->getHeaderLine(self::DAVHeader); |
| 165 | - if(!empty($val)){ |
|
| 165 | + if (!empty($val)) { |
|
| 166 | 166 | $options = explode(', ', $val); |
| 167 | 167 | } |
| 168 | 168 | } |
@@ -176,14 +176,13 @@ discard block |
||
| 176 | 176 | public function getUserPrincipal() |
| 177 | 177 | { |
| 178 | 178 | $http_response = $this->makeRequest( |
| 179 | - RequestFactory::createPropFindRequest |
|
| 180 | - ( |
|
| 179 | + RequestFactory::createPropFindRequest( |
|
| 181 | 180 | $this->server_url, |
| 182 | 181 | CalDAVRequestFactory::getInstance()->build(CalDAVRequestFactory::PrincipalRequestType)->getContent() |
| 183 | 182 | ) |
| 184 | 183 | ); |
| 185 | 184 | |
| 186 | - return new UserPrincipalResponse($this->server_url, (string)$http_response->getBody(), $http_response->getStatusCode()); |
|
| 185 | + return new UserPrincipalResponse($this->server_url, (string) $http_response->getBody(), $http_response->getStatusCode()); |
|
| 187 | 186 | } |
| 188 | 187 | |
| 189 | 188 | /** |
@@ -193,14 +192,13 @@ discard block |
||
| 193 | 192 | public function getCalendarHome($principal_url) |
| 194 | 193 | { |
| 195 | 194 | $http_response = $this->makeRequest( |
| 196 | - RequestFactory::createPropFindRequest |
|
| 197 | - ( |
|
| 195 | + RequestFactory::createPropFindRequest( |
|
| 198 | 196 | $principal_url, |
| 199 | 197 | CalDAVRequestFactory::getInstance()->build(CalDAVRequestFactory::CalendarHomeRequestType)->getContent() |
| 200 | 198 | ) |
| 201 | 199 | ); |
| 202 | 200 | |
| 203 | - return new CalendarHomesResponse($this->server_url, (string)$http_response->getBody(), $http_response->getStatusCode()); |
|
| 201 | + return new CalendarHomesResponse($this->server_url, (string) $http_response->getBody(), $http_response->getStatusCode()); |
|
| 204 | 202 | } |
| 205 | 203 | |
| 206 | 204 | /** |
@@ -212,8 +210,7 @@ discard block |
||
| 212 | 210 | public function createCalendar($calendar_home_set, MakeCalendarRequestVO $vo) |
| 213 | 211 | { |
| 214 | 212 | $http_response = $this->makeRequest( |
| 215 | - RequestFactory::createMakeCalendarRequest |
|
| 216 | - ( |
|
| 213 | + RequestFactory::createMakeCalendarRequest( |
|
| 217 | 214 | $calendar_home_set.$vo->getResourceName(), |
| 218 | 215 | CalDAVRequestFactory::getInstance()->build(CalDAVRequestFactory::CalendarCreateRequestType, [$vo])->getContent() |
| 219 | 216 | ) |
@@ -229,14 +226,13 @@ discard block |
||
| 229 | 226 | public function getCalendars($calendar_home_set_url) |
| 230 | 227 | { |
| 231 | 228 | $http_response = $this->makeRequest( |
| 232 | - RequestFactory::createPropFindRequest |
|
| 233 | - ( |
|
| 229 | + RequestFactory::createPropFindRequest( |
|
| 234 | 230 | $calendar_home_set_url, |
| 235 | 231 | CalDAVRequestFactory::getInstance()->build(CalDAVRequestFactory::CalendarsRequestType)->getContent() |
| 236 | 232 | ) |
| 237 | 233 | ); |
| 238 | 234 | |
| 239 | - return new GetCalendarsResponse($this->server_url, (string)$http_response->getBody(), $http_response->getStatusCode()); |
|
| 235 | + return new GetCalendarsResponse($this->server_url, (string) $http_response->getBody(), $http_response->getStatusCode()); |
|
| 240 | 236 | } |
| 241 | 237 | |
| 242 | 238 | /** |
@@ -246,15 +242,14 @@ discard block |
||
| 246 | 242 | public function getCalendar($calendar_url) |
| 247 | 243 | { |
| 248 | 244 | $http_response = $this->makeRequest( |
| 249 | - RequestFactory::createPropFindRequest |
|
| 250 | - ( |
|
| 245 | + RequestFactory::createPropFindRequest( |
|
| 251 | 246 | $calendar_url, |
| 252 | 247 | CalDAVRequestFactory::getInstance()->build(CalDAVRequestFactory::CalendarRequestType)->getContent(), |
| 253 | 248 | 0 |
| 254 | 249 | ) |
| 255 | 250 | ); |
| 256 | 251 | |
| 257 | - return new GetCalendarResponse($this->server_url, (string)$http_response->getBody(), $http_response->getStatusCode()); |
|
| 252 | + return new GetCalendarResponse($this->server_url, (string) $http_response->getBody(), $http_response->getStatusCode()); |
|
| 258 | 253 | } |
| 259 | 254 | |
| 260 | 255 | |
@@ -267,14 +262,13 @@ discard block |
||
| 267 | 262 | { |
| 268 | 263 | |
| 269 | 264 | $http_response = $this->makeRequest( |
| 270 | - RequestFactory::createReportRequest |
|
| 271 | - ( |
|
| 265 | + RequestFactory::createReportRequest( |
|
| 272 | 266 | $calendar_url, |
| 273 | 267 | CalDAVRequestFactory::getInstance()->build(CalDAVRequestFactory::CalendarSyncRequestType, [$sync_token])->getContent() |
| 274 | 268 | ) |
| 275 | 269 | ); |
| 276 | 270 | |
| 277 | - return new CalendarSyncInfoResponse($this->server_url, (string)$http_response->getBody(), $http_response->getStatusCode()); |
|
| 271 | + return new CalendarSyncInfoResponse($this->server_url, (string) $http_response->getBody(), $http_response->getStatusCode()); |
|
| 278 | 272 | } |
| 279 | 273 | |
| 280 | 274 | /** |
@@ -287,19 +281,17 @@ discard block |
||
| 287 | 281 | $uid = $vo->getUID(); |
| 288 | 282 | $resource_url = $calendar_url.$uid.self::SchedulingInformationSuffix; |
| 289 | 283 | $http_response = $this->makeRequest( |
| 290 | - RequestFactory::createPutRequest |
|
| 291 | - ( |
|
| 284 | + RequestFactory::createPutRequest( |
|
| 292 | 285 | $resource_url, |
| 293 | 286 | CalDAVRequestFactory::getInstance()->build(CalDAVRequestFactory::EventCreateRequestType, [$vo])->getContent() |
| 294 | 287 | ) |
| 295 | 288 | ); |
| 296 | 289 | $etag = $http_response->hasHeader(self::ETagHeader) ? $http_response->getHeaderLine(self::ETagHeader) : null; |
| 297 | - return new EventCreatedResponse |
|
| 298 | - ( |
|
| 290 | + return new EventCreatedResponse( |
|
| 299 | 291 | $uid, |
| 300 | 292 | $etag, |
| 301 | 293 | $resource_url, |
| 302 | - (string)$http_response->getBody(), |
|
| 294 | + (string) $http_response->getBody(), |
|
| 303 | 295 | $http_response->getStatusCode() |
| 304 | 296 | ); |
| 305 | 297 | } |
@@ -315,20 +307,18 @@ discard block |
||
| 315 | 307 | $uid = $vo->getUID(); |
| 316 | 308 | $resource_url = $calendar_url.$uid.self::SchedulingInformationSuffix; |
| 317 | 309 | $http_response = $this->makeRequest( |
| 318 | - RequestFactory::createPutRequest |
|
| 319 | - ( |
|
| 310 | + RequestFactory::createPutRequest( |
|
| 320 | 311 | $resource_url, |
| 321 | 312 | CalDAVRequestFactory::getInstance()->build(CalDAVRequestFactory::EventUpdateRequestType, [$vo])->getContent(), |
| 322 | 313 | $etag |
| 323 | 314 | ) |
| 324 | 315 | ); |
| 325 | 316 | $etag = $http_response->hasHeader(self::ETagHeader) ? $http_response->getHeaderLine(self::ETagHeader) : null; |
| 326 | - return new EventUpdatedResponse |
|
| 327 | - ( |
|
| 317 | + return new EventUpdatedResponse( |
|
| 328 | 318 | $uid, |
| 329 | 319 | $etag, |
| 330 | 320 | $resource_url, |
| 331 | - (string)$http_response->getBody(), |
|
| 321 | + (string) $http_response->getBody(), |
|
| 332 | 322 | $http_response->getStatusCode() |
| 333 | 323 | ); |
| 334 | 324 | } |
@@ -342,16 +332,14 @@ discard block |
||
| 342 | 332 | public function deleteEvent($calendar_url, $uid, $etag) |
| 343 | 333 | { |
| 344 | 334 | $http_response = $this->makeRequest( |
| 345 | - RequestFactory::createDeleteRequest |
|
| 346 | - ( |
|
| 335 | + RequestFactory::createDeleteRequest( |
|
| 347 | 336 | $calendar_url.$uid.self::SchedulingInformationSuffix, |
| 348 | 337 | $etag |
| 349 | 338 | ) |
| 350 | 339 | ); |
| 351 | 340 | |
| 352 | - return new EventDeletedResponse |
|
| 353 | - ( |
|
| 354 | - $this->server_url, (string)$http_response->getBody(), $http_response->getStatusCode() |
|
| 341 | + return new EventDeletedResponse( |
|
| 342 | + $this->server_url, (string) $http_response->getBody(), $http_response->getStatusCode() |
|
| 355 | 343 | ); |
| 356 | 344 | } |
| 357 | 345 | |
@@ -359,15 +347,14 @@ discard block |
||
| 359 | 347 | * @param string $event_url |
| 360 | 348 | * @return string |
| 361 | 349 | */ |
| 362 | - public function getEventVCardBy($event_url){ |
|
| 350 | + public function getEventVCardBy($event_url) { |
|
| 363 | 351 | $http_response = $this->makeRequest( |
| 364 | - RequestFactory::createGetRequest |
|
| 365 | - ( |
|
| 352 | + RequestFactory::createGetRequest( |
|
| 366 | 353 | $event_url |
| 367 | 354 | ) |
| 368 | 355 | ); |
| 369 | 356 | |
| 370 | - $ical = (string)$http_response->getBody(); |
|
| 357 | + $ical = (string) $http_response->getBody(); |
|
| 371 | 358 | return $ical; |
| 372 | 359 | } |
| 373 | 360 | |
@@ -379,17 +366,15 @@ discard block |
||
| 379 | 366 | public function getEventsBy($calendar_url, array $events_urls) |
| 380 | 367 | { |
| 381 | 368 | $http_response = $this->makeRequest( |
| 382 | - RequestFactory::createReportRequest |
|
| 383 | - ( |
|
| 369 | + RequestFactory::createReportRequest( |
|
| 384 | 370 | $calendar_url, |
| 385 | 371 | CalDAVRequestFactory::getInstance()->build(CalDAVRequestFactory::CalendarMultiGetRequestType, [$events_urls])->getContent() |
| 386 | 372 | ) |
| 387 | 373 | ); |
| 388 | 374 | |
| 389 | - return new ResourceCollectionResponse |
|
| 390 | - ( |
|
| 375 | + return new ResourceCollectionResponse( |
|
| 391 | 376 | $this->server_url, |
| 392 | - (string)$http_response->getBody(), |
|
| 377 | + (string) $http_response->getBody(), |
|
| 393 | 378 | $http_response->getStatusCode() |
| 394 | 379 | ); |
| 395 | 380 | } |
@@ -403,17 +388,15 @@ discard block |
||
| 403 | 388 | { |
| 404 | 389 | |
| 405 | 390 | $http_response = $this->makeRequest( |
| 406 | - RequestFactory::createReportRequest |
|
| 407 | - ( |
|
| 391 | + RequestFactory::createReportRequest( |
|
| 408 | 392 | $calendar_url, |
| 409 | 393 | CalDAVRequestFactory::getInstance()->build(CalDAVRequestFactory::CalendarQueryRequestType, [$filter])->getContent() |
| 410 | 394 | ) |
| 411 | 395 | ); |
| 412 | 396 | |
| 413 | - return new ResourceCollectionResponse |
|
| 414 | - ( |
|
| 397 | + return new ResourceCollectionResponse( |
|
| 415 | 398 | $this->server_url, |
| 416 | - (string)$http_response->getBody(), |
|
| 399 | + (string) $http_response->getBody(), |
|
| 417 | 400 | $http_response->getStatusCode() |
| 418 | 401 | ); |
| 419 | 402 | } |
@@ -94,8 +94,7 @@ discard block |
||
| 94 | 94 | * @param string $location_lat |
| 95 | 95 | * @param string $location_lng |
| 96 | 96 | */ |
| 97 | - public function __construct |
|
| 98 | - ( |
|
| 97 | + public function __construct( |
|
| 99 | 98 | $prod_id, |
| 100 | 99 | $title, |
| 101 | 100 | $description, |
@@ -121,7 +120,7 @@ discard block |
||
| 121 | 120 | $this->location_lat = $location_lat; |
| 122 | 121 | $this->location_lng = $location_lng; |
| 123 | 122 | $this->time_zone = $time_zone; |
| 124 | - if(is_null($this->time_zone)){ |
|
| 123 | + if (is_null($this->time_zone)) { |
|
| 125 | 124 | $this->time_zone = new DateTimeZone('UTC'); |
| 126 | 125 | } |
| 127 | 126 | } |
@@ -129,7 +128,7 @@ discard block |
||
| 129 | 128 | /** |
| 130 | 129 | * @param string $uid |
| 131 | 130 | */ |
| 132 | - public function setUID($uid){ |
|
| 131 | + public function setUID($uid) { |
|
| 133 | 132 | $this->uid = $uid; |
| 134 | 133 | } |
| 135 | 134 | |
@@ -216,7 +215,7 @@ discard block |
||
| 216 | 215 | /** |
| 217 | 216 | * @return DateTimeZone |
| 218 | 217 | */ |
| 219 | - public function getTimeZone(){ |
|
| 218 | + public function getTimeZone() { |
|
| 220 | 219 | return $this->time_zone; |
| 221 | 220 | } |
| 222 | 221 | |
@@ -59,17 +59,15 @@ |
||
| 59 | 59 | 'attributes' => ['name' => 'VEVENT'] |
| 60 | 60 | ] |
| 61 | 61 | ], |
| 62 | - '{urn:ietf:params:xml:ns:caldav}calendar-timezone' => new Cdata |
|
| 63 | - ( |
|
| 64 | - ICalTimeZoneBuilder::build |
|
| 65 | - ( |
|
| 62 | + '{urn:ietf:params:xml:ns:caldav}calendar-timezone' => new Cdata( |
|
| 63 | + ICalTimeZoneBuilder::build( |
|
| 66 | 64 | $this->vo->getTimezone(), |
| 67 | 65 | $this->vo->getDisplayName() |
| 68 | 66 | )->render() |
| 69 | 67 | ) |
| 70 | 68 | ]; |
| 71 | 69 | |
| 72 | - if(!empty($this->vo->getDescription())) |
|
| 70 | + if (!empty($this->vo->getDescription())) |
|
| 73 | 71 | $props['{urn:ietf:params:xml:ns:caldav}calendar-description'] = $this->vo->getDescription(); |
| 74 | 72 | |
| 75 | 73 | return $service->write('{urn:ietf:params:xml:ns:caldav}mkcalendar', |
@@ -69,8 +69,9 @@ |
||
| 69 | 69 | ) |
| 70 | 70 | ]; |
| 71 | 71 | |
| 72 | - if(!empty($this->vo->getDescription())) |
|
| 73 | - $props['{urn:ietf:params:xml:ns:caldav}calendar-description'] = $this->vo->getDescription(); |
|
| 72 | + if(!empty($this->vo->getDescription())) { |
|
| 73 | + $props['{urn:ietf:params:xml:ns:caldav}calendar-description'] = $this->vo->getDescription(); |
|
| 74 | + } |
|
| 74 | 75 | |
| 75 | 76 | return $service->write('{urn:ietf:params:xml:ns:caldav}mkcalendar', |
| 76 | 77 | [ |
@@ -57,16 +57,16 @@ |
||
| 57 | 57 | ->setDescription(strip_tags($this->vo->getDescription())) |
| 58 | 58 | ->setDescriptionHTML($this->vo->getDescription()); |
| 59 | 59 | |
| 60 | - if($time_zone->getName() == 'UTC'){ |
|
| 60 | + if ($time_zone->getName() == 'UTC') { |
|
| 61 | 61 | $event->setUseUtc(true) |
| 62 | 62 | ->setUseTimezone(false); |
| 63 | 63 | } |
| 64 | - else{ |
|
| 64 | + else { |
|
| 65 | 65 | $event->setUseUtc(false) |
| 66 | 66 | ->setUseTimezone(true); |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - if(!empty($this->vo->getLocationTitle())){ |
|
| 69 | + if (!empty($this->vo->getLocationTitle())) { |
|
| 70 | 70 | $geo = sprintf("%s;%s", $this->vo->getLocationLat(), $this->vo->getLocationLng()); |
| 71 | 71 | $event->setLocation($this->vo->getLocationTitle(), $this->vo->getLocationTitle(), $geo); |
| 72 | 72 | } |
@@ -55,28 +55,28 @@ |
||
| 55 | 55 | break; |
| 56 | 56 | case HttpMethods::Put: |
| 57 | 57 | { |
| 58 | - $etag = $params[0]; |
|
| 59 | - if(empty($etag)){ |
|
| 60 | - return [ |
|
| 61 | - Headers::ContentType => ContentTypes::Calendar, |
|
| 62 | - Headers::IfNotMatch => '*', |
|
| 63 | - ]; |
|
| 64 | - } |
|
| 65 | - return [ |
|
| 66 | - Headers::ContentType => ContentTypes::Calendar, |
|
| 67 | - Headers::IfMatch => $etag |
|
| 68 | - ]; |
|
| 58 | + $etag = $params[0]; |
|
| 59 | + if(empty($etag)){ |
|
| 60 | + return [ |
|
| 61 | + Headers::ContentType => ContentTypes::Calendar, |
|
| 62 | + Headers::IfNotMatch => '*', |
|
| 63 | + ]; |
|
| 64 | + } |
|
| 65 | + return [ |
|
| 66 | + Headers::ContentType => ContentTypes::Calendar, |
|
| 67 | + Headers::IfMatch => $etag |
|
| 68 | + ]; |
|
| 69 | 69 | } |
| 70 | 70 | break; |
| 71 | 71 | } |
| 72 | 72 | return []; |
| 73 | 73 | } |
| 74 | 74 | /** |
| 75 | - * @param string $url |
|
| 76 | - * @param string $body |
|
| 77 | - * @param int $depth |
|
| 78 | - * @return Request |
|
| 79 | - */ |
|
| 75 | + * @param string $url |
|
| 76 | + * @param string $body |
|
| 77 | + * @param int $depth |
|
| 78 | + * @return Request |
|
| 79 | + */ |
|
| 80 | 80 | static public function createPropFindRequest($url , $body, $depth = 1){ |
| 81 | 81 | return new Request |
| 82 | 82 | ( |
@@ -26,8 +26,8 @@ discard block |
||
| 26 | 26 | * @param array $params |
| 27 | 27 | * @return array |
| 28 | 28 | */ |
| 29 | - static private function createHeadersFor($http_method, array $params = []){ |
|
| 30 | - switch ($http_method){ |
|
| 29 | + static private 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: |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | case HttpMethods::Put: |
| 57 | 57 | { |
| 58 | 58 | $etag = $params[0]; |
| 59 | - if(empty($etag)){ |
|
| 59 | + if (empty($etag)) { |
|
| 60 | 60 | return [ |
| 61 | 61 | Headers::ContentType => ContentTypes::Calendar, |
| 62 | 62 | Headers::IfNotMatch => '*', |
@@ -77,11 +77,10 @@ discard block |
||
| 77 | 77 | * @param int $depth |
| 78 | 78 | * @return Request |
| 79 | 79 | */ |
| 80 | - static public function createPropFindRequest($url , $body, $depth = 1){ |
|
| 81 | - return new Request |
|
| 82 | - ( |
|
| 80 | + static public function createPropFindRequest($url, $body, $depth = 1) { |
|
| 81 | + return new Request( |
|
| 83 | 82 | HttpMethods::PropFind, |
| 84 | - $url , |
|
| 83 | + $url, |
|
| 85 | 84 | self::createHeadersFor(HttpMethods::PropFind, [$depth]), |
| 86 | 85 | $body |
| 87 | 86 | ); |
@@ -92,9 +91,8 @@ discard block |
||
| 92 | 91 | * @param string $body |
| 93 | 92 | * @return Request |
| 94 | 93 | */ |
| 95 | - static public function createMakeCalendarRequest($url , $body){ |
|
| 96 | - return new Request |
|
| 97 | - ( |
|
| 94 | + static public function createMakeCalendarRequest($url, $body) { |
|
| 95 | + return new Request( |
|
| 98 | 96 | HttpMethods::MakeCalendar, |
| 99 | 97 | $url, |
| 100 | 98 | self::createHeadersFor(HttpMethods::MakeCalendar), |
@@ -107,9 +105,8 @@ discard block |
||
| 107 | 105 | * @param int $depth |
| 108 | 106 | * @return Request |
| 109 | 107 | */ |
| 110 | - static public function createOptionsRequest($url, $depth = 1){ |
|
| 111 | - return new Request |
|
| 112 | - ( |
|
| 108 | + static public function createOptionsRequest($url, $depth = 1) { |
|
| 109 | + return new Request( |
|
| 113 | 110 | HttpMethods::Options, |
| 114 | 111 | $url, |
| 115 | 112 | self::createHeadersFor(HttpMethods::Options, [$depth]) |
@@ -122,9 +119,8 @@ discard block |
||
| 122 | 119 | * @param int $depth |
| 123 | 120 | * @return Request |
| 124 | 121 | */ |
| 125 | - static public function createReportRequest($url , $body, $depth = 1){ |
|
| 126 | - return new Request |
|
| 127 | - ( |
|
| 122 | + static public function createReportRequest($url, $body, $depth = 1) { |
|
| 123 | + return new Request( |
|
| 128 | 124 | HttpMethods::Report, |
| 129 | 125 | $url, |
| 130 | 126 | self::createHeadersFor(HttpMethods::Report, [$depth]), |
@@ -137,9 +133,8 @@ discard block |
||
| 137 | 133 | * @param string $etag |
| 138 | 134 | * @return Request |
| 139 | 135 | */ |
| 140 | - static public function createDeleteRequest($url , $etag){ |
|
| 141 | - return new Request |
|
| 142 | - ( |
|
| 136 | + static public function createDeleteRequest($url, $etag) { |
|
| 137 | + return new Request( |
|
| 143 | 138 | HttpMethods::Delete, |
| 144 | 139 | $url, |
| 145 | 140 | self::createHeadersFor(HttpMethods::Delete, [$etag]) |
@@ -150,9 +145,8 @@ discard block |
||
| 150 | 145 | * @param string $url |
| 151 | 146 | * @return Request |
| 152 | 147 | */ |
| 153 | - static public function createGetRequest($url){ |
|
| 154 | - return new Request |
|
| 155 | - ( |
|
| 148 | + static public function createGetRequest($url) { |
|
| 149 | + return new Request( |
|
| 156 | 150 | HttpMethods::Get, |
| 157 | 151 | $url, |
| 158 | 152 | self::createHeadersFor(HttpMethods::Get) |
@@ -165,9 +159,8 @@ discard block |
||
| 165 | 159 | * @param string $etag |
| 166 | 160 | * @return Request |
| 167 | 161 | */ |
| 168 | - static public function createPutRequest($url, $body, $etag = null){ |
|
| 169 | - return new Request |
|
| 170 | - ( |
|
| 162 | + static public function createPutRequest($url, $body, $etag = null) { |
|
| 163 | + return new Request( |
|
| 171 | 164 | HttpMethods::Put, |
| 172 | 165 | $url, |
| 173 | 166 | self::createHeadersFor(HttpMethods::Put, [$etag]), |
@@ -31,11 +31,11 @@ discard block |
||
| 31 | 31 | * @param DateTimeZone $time_zone |
| 32 | 32 | * @return array |
| 33 | 33 | */ |
| 34 | - private static function calculateTimeRangeForTransitions(DateTimeZone $time_zone){ |
|
| 34 | + private static function calculateTimeRangeForTransitions(DateTimeZone $time_zone) { |
|
| 35 | 35 | |
| 36 | 36 | $now = new DateTime('now', $time_zone); |
| 37 | 37 | $year = $now->format('Y'); |
| 38 | - return [new DateTime('1/1/'.$year, $time_zone), new DateTime('1/1/'.($year + 1), $time_zone)]; |
|
| 38 | + return [new DateTime('1/1/'.$year, $time_zone), new DateTime('1/1/'.($year + 1), $time_zone)]; |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | /** |
@@ -43,11 +43,11 @@ discard block |
||
| 43 | 43 | * @param int $former_offset |
| 44 | 44 | * @return DateTime |
| 45 | 45 | */ |
| 46 | - private static function convertStartDateFromUTC2Local(array $trans, $former_offset){ |
|
| 46 | + private static function convertStartDateFromUTC2Local(array $trans, $former_offset) { |
|
| 47 | 47 | $dt = new DateTime($trans['time'], new DateTimeZone('UTC')); |
| 48 | 48 | $hours = abs($former_offset); |
| 49 | 49 | // START TIME IS ON UTC and should be converted to local using former offset |
| 50 | - if($former_offset >= 0 ) |
|
| 50 | + if ($former_offset >= 0) |
|
| 51 | 51 | $dt->add(new DateInterval("PT{$hours}H")); |
| 52 | 52 | else |
| 53 | 53 | $dt->sub(new DateInterval("PT{$hours}H")); |
@@ -59,12 +59,11 @@ discard block |
||
| 59 | 59 | * @param DateTime $dt |
| 60 | 60 | * @return RecurrenceRule |
| 61 | 61 | */ |
| 62 | - private static function calculateRecurrenceRule(DateTime $dt){ |
|
| 63 | - $r_rule = new RecurrenceRule(); |
|
| 62 | + private static function calculateRecurrenceRule(DateTime $dt) { |
|
| 63 | + $r_rule = new RecurrenceRule(); |
|
| 64 | 64 | $r_rule->setFreq(RecurrenceRule::FREQ_YEARLY); |
| 65 | 65 | $r_rule->setByMonth(intval($dt->format('m'))); |
| 66 | - $r_rule->setByDay |
|
| 67 | - ( |
|
| 66 | + $r_rule->setByDay( |
|
| 68 | 67 | self::translate2ByDay($dt) |
| 69 | 68 | ); |
| 70 | 69 | return $r_rule; |
@@ -74,7 +73,7 @@ discard block |
||
| 74 | 73 | * @param $offset |
| 75 | 74 | * @return string |
| 76 | 75 | */ |
| 77 | - private static function calculateOffsetFrom($offset){ |
|
| 76 | + private static function calculateOffsetFrom($offset) { |
|
| 78 | 77 | return sprintf('%s%02d%02d', $offset >= 0 ? '+' : '-', abs($offset), abs(($offset - floor($offset)) * 60)); |
| 79 | 78 | } |
| 80 | 79 | |
@@ -82,7 +81,7 @@ discard block |
||
| 82 | 81 | * @param $offset |
| 83 | 82 | * @return string |
| 84 | 83 | */ |
| 85 | - private static function calculateOffsetTo($offset){ |
|
| 84 | + private static function calculateOffsetTo($offset) { |
|
| 86 | 85 | return sprintf('%s%02d%02d', $offset >= 0 ? '+' : '-', abs($offset), abs(($offset - floor($offset)) * 60)); |
| 87 | 86 | } |
| 88 | 87 | /** |
@@ -91,7 +90,7 @@ discard block |
||
| 91 | 90 | * @param bool $with_calendar_envelope |
| 92 | 91 | * @return Calendar|Timezone |
| 93 | 92 | */ |
| 94 | - public static function build(DateTimeZone $time_zone, $calendar_prod_id, $with_calendar_envelope = true){ |
|
| 93 | + public static function build(DateTimeZone $time_zone, $calendar_prod_id, $with_calendar_envelope = true) { |
|
| 95 | 94 | |
| 96 | 95 | // get all transitions for one current year and next |
| 97 | 96 | list($start_range, $end_range) = self::calculateTimeRangeForTransitions($time_zone); |
@@ -111,11 +110,11 @@ discard block |
||
| 111 | 110 | |
| 112 | 111 | // daylight saving time definition |
| 113 | 112 | if ($trans['isdst']) { |
| 114 | - $current_time_zone_rule = new TimezoneRule(TimezoneRule::TYPE_DAYLIGHT);; |
|
| 113 | + $current_time_zone_rule = new TimezoneRule(TimezoneRule::TYPE_DAYLIGHT); ; |
|
| 115 | 114 | } |
| 116 | 115 | // standard time definition |
| 117 | 116 | else { |
| 118 | - $current_time_zone_rule = new TimezoneRule(TimezoneRule::TYPE_STANDARD);; |
|
| 117 | + $current_time_zone_rule = new TimezoneRule(TimezoneRule::TYPE_STANDARD); ; |
|
| 119 | 118 | } |
| 120 | 119 | |
| 121 | 120 | if ($current_time_zone_rule) { |
@@ -136,7 +135,7 @@ discard block |
||
| 136 | 135 | } |
| 137 | 136 | |
| 138 | 137 | } |
| 139 | - if($with_calendar_envelope) { |
|
| 138 | + if ($with_calendar_envelope) { |
|
| 140 | 139 | $vCalendar = new Calendar(sprintf("'-//%s//EN'", $calendar_prod_id)); |
| 141 | 140 | $vCalendar->setTimezone($vTimezone); |
| 142 | 141 | return $vCalendar; |
@@ -156,25 +155,25 @@ discard block |
||
| 156 | 155 | * @param DateTime $dt) |
| 157 | 156 | * @return string |
| 158 | 157 | */ |
| 159 | - private static function translate2ByDay(DateTime $dt){ |
|
| 160 | - $day_name = substr(strtoupper($dt->format('D')), 0,2); |
|
| 158 | + private static function translate2ByDay(DateTime $dt) { |
|
| 159 | + $day_name = substr(strtoupper($dt->format('D')), 0, 2); |
|
| 161 | 160 | $ordinals = ['first', 'second', 'third', 'fourth', 'last']; |
| 162 | 161 | $day_nbr = 0; |
| 163 | 162 | $is_last = false; |
| 164 | 163 | |
| 165 | - foreach($ordinals as $idx => $ord){ |
|
| 164 | + foreach ($ordinals as $idx => $ord) { |
|
| 166 | 165 | $dt_n = self::buildOrdinalDateTime($ord, $dt); |
| 167 | - if($dt_n->format('Y-m-d') == $dt->format('Y-m-d')){ |
|
| 168 | - $day_nbr = $idx + 1; |
|
| 169 | - if($ord == 'last'){ |
|
| 166 | + if ($dt_n->format('Y-m-d') == $dt->format('Y-m-d')) { |
|
| 167 | + $day_nbr = $idx + 1; |
|
| 168 | + if ($ord == 'last') { |
|
| 170 | 169 | $is_last = true; |
| 171 | - $day_nbr = 1; |
|
| 170 | + $day_nbr = 1; |
|
| 172 | 171 | } |
| 173 | 172 | break; |
| 174 | 173 | } |
| 175 | 174 | } |
| 176 | 175 | |
| 177 | - return sprintf('%s%s%s', $is_last? '-':'', $day_nbr, $day_name); |
|
| 176 | + return sprintf('%s%s%s', $is_last ? '-' : '', $day_nbr, $day_name); |
|
| 178 | 177 | } |
| 179 | 178 | |
| 180 | 179 | /** |
@@ -182,15 +181,11 @@ discard block |
||
| 182 | 181 | * @param DateTime $dt |
| 183 | 182 | * @return DateTime |
| 184 | 183 | */ |
| 185 | - private static function buildOrdinalDateTime($ord, DateTime $dt){ |
|
| 186 | - return new DateTime |
|
| 187 | - ( |
|
| 188 | - date |
|
| 189 | - ("Y-m-d", |
|
| 190 | - strtotime |
|
| 191 | - ( |
|
| 192 | - sprintf |
|
| 193 | - ( |
|
| 184 | + private static function buildOrdinalDateTime($ord, DateTime $dt) { |
|
| 185 | + return new DateTime( |
|
| 186 | + date("Y-m-d", |
|
| 187 | + strtotime( |
|
| 188 | + sprintf( |
|
| 194 | 189 | self::GetOrdinalDayQuery, |
| 195 | 190 | $ord, |
| 196 | 191 | $dt->format('l'), |
@@ -47,10 +47,11 @@ |
||
| 47 | 47 | $dt = new DateTime($trans['time'], new DateTimeZone('UTC')); |
| 48 | 48 | $hours = abs($former_offset); |
| 49 | 49 | // START TIME IS ON UTC and should be converted to local using former offset |
| 50 | - if($former_offset >= 0 ) |
|
| 51 | - $dt->add(new DateInterval("PT{$hours}H")); |
|
| 52 | - else |
|
| 53 | - $dt->sub(new DateInterval("PT{$hours}H")); |
|
| 50 | + if($former_offset >= 0 ) { |
|
| 51 | + $dt->add(new DateInterval("PT{$hours}H")); |
|
| 52 | + } else { |
|
| 53 | + $dt->sub(new DateInterval("PT{$hours}H")); |
|
| 54 | + } |
|
| 54 | 55 | |
| 55 | 56 | return $dt; |
| 56 | 57 | } |