/** * Translate expression to xpath * * @param string $expression * @return string */ public function convertToXpath($expression) { if (!is_string($expression)) { throw new \InvalidArgumentException('Expect expression to be the type of string. Given: ' . gettype($expression)); } $expression = trim($expression); if (empty($expression)) { throw new \InvalidArgumentException('Expect not empty expression'); } if ($expression === '.') { return $expression; } if (strpos($expression, './') === 0) { return $expression; } $firstChar = substr($expression, 0, 1); if (in_array($firstChar, ['/', '('])) { return $expression; } return $this->cssTranslator->convertToXpath($expression); }
/** * @param string $expression * @return string */ private function convertExpression($expression) { return $this->expressionTranslator->convertToXpath($expression); }