clientFactory = $clientFactory; $this->gateway = $gateway; } /** * @param int $userId * * @throws GoogleAccountNotFoundException * @throws GoogleApiAccessException * @throws GoogleApiScopeException * * @return GoogleCalendarClient */ public function createClient(int $userId): GoogleCalendarClient { try { $apiClient = $this->clientFactory->createClient($userId); } catch (AccountNotFoundException $e) { throw new GoogleAccountNotFoundException($e->getMessage(), $e->getCode(), $e); } catch (AccessException $e) { throw new GoogleApiAccessException($e->getMessage(), $e->getCode(), $e); } $account = $apiClient->getAccount(); if (!$this->gateway->hasAccountScope($account->getId(), GoogleScope::CALENDAR)) { $this->logger->debug( 'User (id={id}) has not granted access to the google calendar API', ['id' => $account->getUserId()] ); throw new GoogleApiScopeException('Access to Google calendar API scope denied'); } $client = new GoogleCalendarClient($apiClient); $client->setLogger($this->logger); return $client; } }