diff --git a/src/Facade/CalDavClient.php b/src/Facade/CalDavClient.php index 09f542d..70affeb 100644 --- a/src/Facade/CalDavClient.php +++ b/src/Facade/CalDavClient.php @@ -20,7 +20,7 @@ use CalDAVClient\Facade\Requests\EventRequestVO; use CalDAVClient\Facade\Requests\MakeCalendarRequestVO; use CalDAVClient\Facade\Responses\CalendarDeletedResponse; -use CalDAVClient\Facade\Responses\CalendarHomesResponse; +use CalDAVClient\Facade\Responses\CalendarHomesMultiResponse; use CalDAVClient\Facade\Responses\CalendarSyncInfoResponse; use CalDAVClient\Facade\Responses\EventCreatedResponse; use CalDAVClient\Facade\Responses\EventDeletedResponse; @@ -208,7 +208,7 @@ public function getUserPrincipal() /** * @param string $principal_url - * @return CalendarHomesResponse + * @return CalendarHomesMultiResponse * @throws \GuzzleHttp\Exception\GuzzleException */ public function getCalendarHome($principal_url) @@ -221,7 +221,7 @@ public function getCalendarHome($principal_url) ) ); - return new CalendarHomesResponse($this->server_url, (string)$http_response->getBody(), $http_response->getStatusCode()); + return new CalendarHomesMultiResponse($this->server_url, (string)$http_response->getBody(), $http_response->getStatusCode()); } /** diff --git a/src/Facade/Responses/CalendarHomesMultiResponse.php b/src/Facade/Responses/CalendarHomesMultiResponse.php new file mode 100644 index 0000000..6b29716 --- /dev/null +++ b/src/Facade/Responses/CalendarHomesMultiResponse.php @@ -0,0 +1,30 @@ +testPrincipal(); - $res = self::$client->getCalendarHome($caldav_host . $principal_url); - $url = $res->getCalendarHomeSetUrl(); - - $this->assertTrue(!empty($url), "Calendar home URL is empty"); - // $host = $res->getRealCalDAVHost(); - // echo sprintf('calendar home is %s', $url).PHP_EOL; - // echo sprintf('host is %s', $caldav_host).PHP_EOL; - - // first, ensures that the 'home' path is relative to the CalDav server - // (this differs between servers) - $path_without_prefix = $url; - if (strpos($path_without_prefix, $caldav_host) === 0) { - $path_without_prefix = substr($path_without_prefix, strlen($caldav_host)); + $homes = self::$client->getCalendarHome($caldav_host . $principal_url)->getResponses(); + foreach ($homes as $res) { + $url = $res->getCalendarHomeSetUrl(); + + $this->assertTrue(!empty($url), "Calendar home URL is empty"); + // $host = $res->getRealCalDAVHost(); + // echo sprintf('calendar home is %s', $url).PHP_EOL; + // echo sprintf('host is %s', $caldav_host).PHP_EOL; + + // first, ensures that the 'home' path is relative to the CalDav server + // (this differs between servers) + $path_without_prefix = $url; + if (strpos($path_without_prefix, $caldav_host) === 0) { + $path_without_prefix = substr($path_without_prefix, strlen($caldav_host)); + } + if (strpos($path_without_prefix, $caldav_path) === 0) { + $path_without_prefix = substr($path_without_prefix, strlen($caldav_path)); + } + + // then, turn the URL into an absolute URL so that we always know what to expect + self::$calendar_home = $caldav_host . $caldav_path . $path_without_prefix; + + // stop after first response + break; } - if (strpos($path_without_prefix, $caldav_path) === 0) { - $path_without_prefix = substr($path_without_prefix, strlen($caldav_path)); - } - - // then, turn the URL into an absolute URL so that we always know what to expect - self::$calendar_home = $caldav_host . $caldav_path . $path_without_prefix; } function testGetCalendars(){