You are here

public function FeedsFileFetcher::fetch in Feeds 7.2

Same name and namespace in other branches
  1. 6 plugins/FeedsFileFetcher.inc \FeedsFileFetcher::fetch()
  2. 7 plugins/FeedsFileFetcher.inc \FeedsFileFetcher::fetch()

Implements FeedsFetcher::fetch().

Overrides FeedsFetcher::fetch

File

plugins/FeedsFileFetcher.inc, line 47
Home of the FeedsFileFetcher and related classes.

Class

FeedsFileFetcher
Fetches data via HTTP.

Code

public function fetch(FeedsSource $source) {
  $source_config = $source
    ->getConfigFor($this);

  // Just return a file fetcher result if this is a file.
  if (is_file($source_config['source'])) {
    return new FeedsFileFetcherResult($source_config['source']);
  }

  // Batch if this is a directory.
  $state = $source
    ->state(FEEDS_FETCH);
  $files = array();
  if (!isset($state->files)) {
    $state->files = $this
      ->listFiles($source_config['source']);
    $state->total = count($state->files);
  }
  if (count($state->files)) {
    $file = array_shift($state->files);
    $state
      ->progress($state->total, $state->total - count($state->files));
    return new FeedsFileFetcherResult($file);
  }
  throw new Exception(t('Resource is not a file or it is an empty directory: %source', array(
    '%source' => $source_config['source'],
  )));
}