You are here

protected function FeedsExJsonPath::validateExpression in Feeds extensible parsers 7

Same name and namespace in other branches
  1. 7.2 src/FeedsExJsonPath.inc \FeedsExJsonPath::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/FeedsExJsonPath.inc, line 68
Contains FeedsExJsonPath.

Class

FeedsExJsonPath
Parses JSON via JSONPath.

Code

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

  // Try to validate if possible.
  if (!class_exists('Flow\\JSONPath\\JSONPathLexer')) {
    return;
  }
  try {

    // Use class as string for PHP 5.2 compat.
    $class = 'Flow\\JSONPath\\JSONPathLexer';
    $lexer = new $class($expression);
    $lexer
      ->parseExpression();
  } catch (Exception $e) {
    return check_plain($e
      ->getMessage());
  }
}