You are here

public function FeedsExBase::parse in Feeds extensible parsers 7

Same name and namespace in other branches
  1. 7.2 src/FeedsExBase.inc \FeedsExBase::parse()

File

src/FeedsExBase.inc, line 182
Contains FeedsExBase.

Class

FeedsExBase
The Feeds extensible parser.

Code

public function parse(FeedsSource $source, FeedsFetcherResult $fetcher_result) {
  $this
    ->loadLibrary();
  $this
    ->startErrorHandling();
  $result = new FeedsParserResult();

  // Set link.
  $fetcher_config = $source
    ->getConfigFor($source->importer->fetcher);
  $result->link = isset($fetcher_config['source']) && is_string($fetcher_config['source']) ? $fetcher_config['source'] : '';
  try {
    $this
      ->setUp($source, $fetcher_result);
    $this
      ->parseItems($source, $fetcher_result, $result);
    $this
      ->cleanUp($source, $result);
  } catch (FeedsExEmptyException $e) {

    // The feed is empty.
    $this
      ->getMessenger()
      ->setMessage(t('The feed is empty.'), 'warning', FALSE);
  } catch (Exception $exception) {

    // Do nothing. Store for later.
  }

  // Display and log errors.
  $errors = $this
    ->getErrors();
  $this
    ->printErrors($errors, $this->config['display_errors'] ? WATCHDOG_DEBUG : WATCHDOG_ERROR);
  $this
    ->logErrors($source, $errors);
  $this
    ->stopErrorHandling();
  if (isset($exception)) {
    throw $exception;
  }
  return $result;
}