You are here

protected function FeedsExJsonPath::executeContext in Feeds extensible parsers 7

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

Returns rows to be parsed.

Parameters

FeedsSource $source: Source information.

FeedsFetcherResult $fetcher_result: The result returned by the fetcher.

Return value

array|Traversable Some iterable that returns rows.

Overrides FeedsExBase::executeContext

File

src/FeedsExJsonPath.inc, line 23
Contains FeedsExJsonPath.

Class

FeedsExJsonPath
Parses JSON via JSONPath.

Code

protected function executeContext(FeedsSource $source, FeedsFetcherResult $fetcher_result) {
  $raw = $this
    ->prepareRaw($fetcher_result);
  $parsed = FeedsExJsonUtility::decodeJsonArray($raw);
  $parsed = $this
    ->getParser()
    ->search($parsed, $this->config['context']['value']);
  if (!is_array($parsed) || empty($parsed)) {
    throw new RuntimeException(t('The context expression must return an object or array.'));
  }
  $state = $source
    ->state(FEEDS_PARSE);
  if (!$state->total) {
    $state->total = count($parsed);
  }
  $start = (int) $state->pointer;
  $state->pointer = $start + $source->importer
    ->getLimit();
  return array_slice($parsed, $start, $source->importer
    ->getLimit());
}