You are here

protected function FeedsExJmesPath::executeSourceExpression in Feeds extensible parsers 7

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

Executes a single source expression.

Parameters

string $machine_name: The source machine name being executed.

string $expression: The expression to execute.

mixed $row: The row to execute on.

Return value

scalar|[]scalar Either a scalar, or a list of scalars. If null, the value will be ignored.

Overrides FeedsExBase::executeSourceExpression

File

src/FeedsExJmesPath.inc, line 195
Contains FeedsExJmesPath.

Class

FeedsExJmesPath
Parses JSON documents with JMESPath.

Code

protected function executeSourceExpression($machine_name, $expression, $row) {
  try {
    $result = $this
      ->search($expression, $row);
  } catch (Exception $e) {

    // There was an error executing this expression, nothing we can do about
    // it.
    return;
  }
  if (is_object($result)) {
    $result = (array) $result;
  }
  if (!is_array($result)) {
    return $result;
  }
  $count = count($result);
  if ($count === 0) {
    return;
  }
  return count($result) === 1 ? reset($result) : array_values($result);
}