You are here

public function HttpFetcher::fetch in Feeds 8.3

Fetch content from a feed and return it.

Parameters

\Drupal\feeds\FeedInterface $feed: The feed to fetch results for.

\Drupal\feeds\StateInterface $state: The state object.

Return value

\Drupal\feeds\Result\FetcherResultInterface A fetcher result object.

Overrides FetcherInterface::fetch

File

src/Feeds/Fetcher/HttpFetcher.php, line 98

Class

HttpFetcher
Defines an HTTP fetcher.

Namespace

Drupal\feeds\Feeds\Fetcher

Code

public function fetch(FeedInterface $feed, StateInterface $state) {
  $sink = $this->fileSystem
    ->tempnam('temporary://', 'feeds_http_fetcher');
  $sink = $this->fileSystem
    ->realpath($sink);

  // Get cache key if caching is enabled.
  $cache_key = $this
    ->useCache() ? $this
    ->getCacheKey($feed) : FALSE;
  $response = $this
    ->get($feed
    ->getSource(), $sink, $cache_key);

  // @todo Handle redirects.
  // @codingStandardsIgnoreStart
  // $feed->setSource($response->getEffectiveUrl());
  // @codingStandardsIgnoreEnd
  // 304, nothing to see here.
  if ($response
    ->getStatusCode() == Response::HTTP_NOT_MODIFIED) {
    $state
      ->setMessage($this
      ->t('The feed has not been updated.'));
    throw new EmptyFeedException();
  }
  return new HttpFetcherResult($sink, $response
    ->getHeaders());
}