You are here

protected function FeedsExJmesPath::executeContext in Feeds extensible parsers 7.2

Same name and namespace in other branches
  1. 7 src/FeedsExJmesPath.inc \FeedsExJmesPath::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

1 method overrides FeedsExJmesPath::executeContext()
FeedsExJmesPathLines::executeContext in src/FeedsExJmesPathLines.inc
Returns rows to be parsed.

File

src/FeedsExJmesPath.inc, line 33
Contains FeedsExJmesPath.

Class

FeedsExJmesPath
Parses JSON documents with JMESPath.

Code

protected function executeContext(FeedsSource $source, FeedsFetcherResult $fetcher_result) {
  $raw = trim($fetcher_result
    ->getRaw());
  if (!strlen($raw)) {
    throw new FeedsExEmptyException();
  }
  if ($encoding = $this
    ->detectEncoding($raw)) {
    $raw = $this
      ->convertEncoding($raw, $encoding);
  }
  $parsed = drupal_json_decode($raw);
  $parsed = $this->jmesPath
    ->search($this->config['context']['value'], $parsed);
  $state = $source
    ->state(FEEDS_PARSE);
  if (!$state->total) {
    $state->total = count($parsed);
  }

  // @todo Consider using array slice syntax when it is supported.
  $start = $state->pointer ? $state->pointer : 0;
  $state->pointer = $start + $source->importer
    ->getLimit();
  return array_slice($parsed, $start, $source->importer
    ->getLimit());
}