You are here

protected function FeedsJSONPathParser::parseSourceElement in Feeds JSONPath Parser 6

Same name and namespace in other branches
  1. 7 FeedsJSONPathParser.inc \FeedsJSONPathParser::parseSourceElement()

Parses one item from the context array.

Parameters

$item: A PHP array.

$query: A JSONPath query.

Return value

array An array containing the results of the query.

1 call to FeedsJSONPathParser::parseSourceElement()
FeedsJSONPathParser::parse in ./FeedsJSONPathParser.inc
Implementation of FeedsParser::parse().

File

./FeedsJSONPathParser.inc, line 103
Provides the Class for Feeds JSONPath Parser.

Class

FeedsJSONPathParser
Base class for the HTML and XML parsers.

Code

protected function parseSourceElement($item, $query, $source) {
  if (empty($query)) {
    return;
  }
  $results = $this
    ->jsonPath($item, $query);
  $this
    ->debug($results, $source);
  unset($item);

  /**
   * If there is one result, return it directly.  If there are no results,
   * return. Otherwise return the results.
   */
  if (count($results) === 1) {
    return $results[0];
  }
  if (count($results) === 0) {
    return;
  }
  return $results;
}