From d0c76f8729c82133fd3311dffa10016f5ec6b6da Mon Sep 17 00:00:00 2001 From: Edward Akerboom Date: Wed, 13 Jun 2018 13:13:46 +0200 Subject: [PATCH 1/3] Add CalendarHomesMultiResponse Principals can have subprincipals (calendar-proxy-read and calendar-proxy-write) in which case more than one CalendarHomeResponse is returned. --- src/Facade/CalDavClient.php | 6 ++-- .../Responses/CalendarHomesMultiResponse.php | 30 +++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 src/Facade/Responses/CalendarHomesMultiResponse.php 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 @@ + Date: Wed, 13 Jun 2018 14:27:49 +0200 Subject: [PATCH 2/3] Fix tests --- tests/FacadeTest.php | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/tests/FacadeTest.php b/tests/FacadeTest.php index 5cf8dd2..59f9cce 100644 --- a/tests/FacadeTest.php +++ b/tests/FacadeTest.php @@ -86,26 +86,31 @@ function testCalendarHomes(){ $caldav_path = getenv("CALDAV_SERVER_PATH"); $principal_url = $this->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(){ From 2a93fc58a9509e799598d2e145341a23a140b645 Mon Sep 17 00:00:00 2001 From: Edward Akerboom Date: Wed, 13 Jun 2018 14:28:18 +0200 Subject: [PATCH 3/3] GetCalendarHome returns a multi response --- src/ICalDavClient.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ICalDavClient.php b/src/ICalDavClient.php index a706c05..b2b978c 100644 --- a/src/ICalDavClient.php +++ b/src/ICalDavClient.php @@ -16,7 +16,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; @@ -59,7 +59,7 @@ public function getUserPrincipal(); /** * @param string $principal_url - * @return CalendarHomesResponse + * @return CalendarHomesMultiResponse */ public function getCalendarHome($principal_url);