protected function FeedsExJsonPath::executeContext in Feeds extensible parsers 7.2
Same name and namespace in other branches
- 7 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
1 method overrides FeedsExJsonPath::executeContext()
- FeedsExJsonPathLines::executeContext in src/
FeedsExJsonPathLines.inc - Returns rows to be parsed.
File
- src/
FeedsExJsonPath.inc, line 16 - Contains FeedsExJsonPath.
Class
- FeedsExJsonPath
- Parses JSON via JSONPath.
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 = jsonPath($parsed, $this->config['context']['value']);
$state = $source
->state(FEEDS_PARSE);
if (!$state->total) {
$state->total = count($parsed);
}
$start = $state->pointer ? $state->pointer : 0;
$state->pointer = $start + $source->importer
->getLimit();
return array_slice($parsed, $start, $source->importer
->getLimit());
}