You are here

public function FunctionExtension::translateContains in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/css-selector/XPath/Extension/FunctionExtension.php \Symfony\Component\CssSelector\XPath\Extension\FunctionExtension::translateContains()

Parameters

XPathExpr $xpath:

FunctionNode $function:

Return value

XPathExpr

Throws

ExpressionErrorException

File

vendor/symfony/css-selector/XPath/Extension/FunctionExtension.php, line 158

Class

FunctionExtension
XPath expression translator function extension.

Namespace

Symfony\Component\CssSelector\XPath\Extension

Code

public function translateContains(XPathExpr $xpath, FunctionNode $function) {
  $arguments = $function
    ->getArguments();
  foreach ($arguments as $token) {
    if (!($token
      ->isString() || $token
      ->isIdentifier())) {
      throw new ExpressionErrorException('Expected a single string or identifier for :contains(), got ' . implode(', ', $arguments));
    }
  }
  return $xpath
    ->addCondition(sprintf('contains(string(.), %s)', Translator::getXpathLiteral($arguments[0]
    ->getValue())));
}