You are here

protected function JmesPathParser::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/JmesPathParser.php, line 160

Class

JmesPathParser
Defines a JSON parser using JMESPath.

Namespace

Drupal\feeds_ex\Feeds\Parser

Code

protected function validateExpression(&$expression) {
  $expression = trim($expression);
  if (!strlen($expression)) {
    return;
  }
  try {
    $this
      ->search($expression, []);
  } catch (SyntaxErrorException $e) {
    return $this
      ->formatSyntaxError($e
      ->getMessage());
  } catch (\RuntimeException $e) {
    if (strpos($e
      ->getMessage(), 'Argument 0') === 0) {

      // Ignore 'Argument 0 errors'.
      return;
    }

    // In all other cases, rethrow the exception.
    throw $e;
  }
}