protected function FeedsExJmesPath::executeContext in Feeds extensible parsers 7
Same name and namespace in other branches
- 7.2 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
File
- src/
FeedsExJmesPath.inc, line 156 - Contains FeedsExJmesPath.
Class
- FeedsExJmesPath
- Parses JSON documents with JMESPath.
Code
protected function executeContext(FeedsSource $source, FeedsFetcherResult $fetcher_result) {
$parsed = FeedsExJsonUtility::decodeJsonObject($this
->prepareRaw($fetcher_result));
$parsed = $this
->search($this->config['context']['value'], $parsed);
if (!is_array($parsed) && !is_object($parsed)) {
throw new RuntimeException(t('The context expression must return an object or array.'));
}
// If an object is returned, consider it one item.
if (is_object($parsed)) {
return array(
$parsed,
);
}
$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());
}