You are here

public static function Reader::importRemoteFeed in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/zendframework/zend-feed/src/Reader/Reader.php \Zend\Feed\Reader\Reader::importRemoteFeed()

Import a feed from a remote URI

Performs similarly to import(), except it uses the HTTP client passed to the method, and does not take into account cached data.

Primary purpose is to make it possible to use the Reader with alternate HTTP client implementations.

Parameters

string $uri:

Http\ClientInterface $client:

Return value

self

Throws

Exception\RuntimeException if response is not an Http\ResponseInterface

Overrides ReaderImportInterface::importRemoteFeed

File

vendor/zendframework/zend-feed/src/Reader/Reader.php, line 270

Class

Reader

Namespace

Zend\Feed\Reader

Code

public static function importRemoteFeed($uri, Http\ClientInterface $client) {
  $response = $client
    ->get($uri);
  if (!$response instanceof Http\ResponseInterface) {
    throw new Exception\RuntimeException(sprintf('Did not receive a %s\\Http\\ResponseInterface from the provided HTTP client; received "%s"', __NAMESPACE__, is_object($response) ? get_class($response) : gettype($response)));
  }
  if ((int) $response
    ->getStatusCode() !== 200) {
    throw new Exception\RuntimeException('Feed failed to load, got response code ' . $response
      ->getStatusCode());
  }
  $reader = static::importString($response
    ->getBody());
  $reader
    ->setOriginalSourceUri($uri);
  return $reader;
}