You are here

protected function JsonPathLinesParser::parseItems in Feeds extensible parsers 8

Performs the actual parsing.

Parameters

\Drupal\feeds\FeedInterface $feed: The feed source.

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

\Drupal\feeds\Result\ParserResultInterface $result: The parser result object to populate.

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

Overrides ParserBase::parseItems

File

src/Feeds/Parser/JsonPathLinesParser.php, line 58

Class

JsonPathLinesParser
Defines a JSON Lines parser using JSONPath.

Namespace

Drupal\feeds_ex\Feeds\Parser

Code

protected function parseItems(FeedInterface $feed, FetcherResultInterface $fetcher_result, ParserResultInterface $result, StateInterface $state) {
  $expressions = $this
    ->prepareExpressions();
  $variable_map = $this
    ->prepareVariables($expressions);
  foreach ($this->iterator as $row) {
    $row = $this
      ->getEncoder()
      ->convertEncoding($row);
    try {
      $row = $this->utility
        ->decodeJsonArray($row);
    } catch (RuntimeException $e) {

      // An array wasn't returned. Skip this item.
      continue;
    }
    if ($item = $this
      ->executeSources($row, $expressions, $variable_map)) {
      $result
        ->addItem($item);
    }
  }
}