You are here

protected function JsonPathParser::validateExpression in Feeds extensible parsers 8

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 ParserBase::validateExpression

File

src/Feeds/Parser/JsonPathParser.php, line 67

Class

JsonPathParser
Defines a JSON parser using JSONPath.

Namespace

Drupal\feeds_ex\Feeds\Parser

Code

protected function validateExpression(&$expression) {
  $expression = trim($expression);

  // Try to validate if possible.
  if (!class_exists('Flow\\JSONPath\\JSONPathLexer')) {
    return;
  }
  try {
    $lexer = new JSONPathLexer($expression);
    $lexer
      ->parseExpression();
  } catch (\Exception $e) {
    return $e
      ->getMessage();
  }
}