httpClient = $httpClient; $this->urlBuilder = $urlBuilder; $this->logger = $logger; } /** * @inheritdoc */ public function getContent($version, $edition, $locale) { $result = false; try { $result = $this->retrieveContent($version, $edition, $locale); if (!$result) { $result = $this->retrieveContent($version, $edition, Locale::DEFAULT_SYSTEM_LOCALE); if (!$result) { $result = $this->retrieveContent($version, '', 'default'); } } } catch (\Exception $e) { $this->logger->warning( sprintf( 'Failed to retrieve the release notification content. The response is: %s', empty($result) ? 'Response body is empty.' : $result ) ); } return $result; } /** * Retrieve content from given url * * @param string $version * @param string $edition * @param string $locale * @return bool|string */ private function retrieveContent($version, $edition, $locale) { $url = $this->urlBuilder->getUrl($version, $edition, $locale); return empty($url) ? false : $this->getResponse($url); } /** * Returns the response body from the HTTP client * * @param $url * @return string */ private function getResponse($url) { $this->httpClient->get($url); $responseBody = $this->httpClient->getBody(); if ($this->httpClient->getStatus() === 200 && !empty($responseBody)) { return $responseBody; } return false; } }