You are here

protected function FeedsExJmesPath::validateExpression in Feeds extensible parsers 7.2

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

Validates an expression.

Parameters

string &$expression: The expression to validate.

Return value

string|null Return the error string, or null if validation was passed.

Overrides FeedsExBase::validateExpression

File

src/FeedsExJmesPath.inc, line 85
Contains FeedsExJmesPath.

Class

FeedsExJmesPath
Parses JSON documents with JMESPath.

Code

protected function validateExpression(&$expression) {
  $expression = trim($expression);
  if (!$expression) {
    return;
  }
  $parser = new AstRuntime();
  try {
    $parser
      ->search($expression, array());
  } catch (SyntaxErrorException $e) {

    // Remove newlines after nl2br() to make testing easier.
    return str_replace("\n", '', nl2br(check_plain(trim($e
      ->getMessage()))));
  }
}