You are here

public function OpmlParser::parse in Feeds 8.3

Parses content returned by fetcher.

@todo This needs more documentation.

Parameters

\Drupal\feeds\FeedInterface $feed: The feed we are parsing for.

\Drupal\feeds\Result\FetcherResultInterface $fetcher_result: The result returned by the fetcher.

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

Return value

\Drupal\feeds\Result\ParserResultInterface The parser result object.

Overrides ParserInterface::parse

File

src/Feeds/Parser/OpmlParser.php, line 29

Class

OpmlParser
Defines an OPML feed parser.

Namespace

Drupal\feeds\Feeds\Parser

Code

public function parse(FeedInterface $feed, FetcherResultInterface $fetcher_result, StateInterface $state) {
  $raw = $fetcher_result
    ->getRaw();
  if (!strlen(trim($raw))) {
    throw new EmptyFeedException();
  }
  $result = new ParserResult();
  $parser = new GenericOpmlParser($fetcher_result
    ->getRaw());
  $opml = $parser
    ->parse(TRUE);
  foreach ($this
    ->getItems($opml['outlines']) as $item) {
    $item
      ->set('feed_title', $opml['head']['#title']);
    $result
      ->addItem($item);
  }
  return $result;
}