comparison vendor/symfony/css-selector/XPath/Extension/FunctionExtension.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 1fec387a4317
children
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
33 /** 33 /**
34 * {@inheritdoc} 34 * {@inheritdoc}
35 */ 35 */
36 public function getFunctionTranslators() 36 public function getFunctionTranslators()
37 { 37 {
38 return array( 38 return [
39 'nth-child' => array($this, 'translateNthChild'), 39 'nth-child' => [$this, 'translateNthChild'],
40 'nth-last-child' => array($this, 'translateNthLastChild'), 40 'nth-last-child' => [$this, 'translateNthLastChild'],
41 'nth-of-type' => array($this, 'translateNthOfType'), 41 'nth-of-type' => [$this, 'translateNthOfType'],
42 'nth-last-of-type' => array($this, 'translateNthLastOfType'), 42 'nth-last-of-type' => [$this, 'translateNthLastOfType'],
43 'contains' => array($this, 'translateContains'), 43 'contains' => [$this, 'translateContains'],
44 'lang' => array($this, 'translateLang'), 44 'lang' => [$this, 'translateLang'],
45 ); 45 ];
46 } 46 }
47 47
48 /** 48 /**
49 * @param XPathExpr $xpath 49 * @param XPathExpr $xpath
50 * @param FunctionNode $function 50 * @param FunctionNode $function
91 91
92 if (0 !== $b) { 92 if (0 !== $b) {
93 $expr .= ' - '.$b; 93 $expr .= ' - '.$b;
94 } 94 }
95 95
96 $conditions = array(sprintf('%s %s 0', $expr, $sign)); 96 $conditions = [sprintf('%s %s 0', $expr, $sign)];
97 97
98 if (1 !== $a && -1 !== $a) { 98 if (1 !== $a && -1 !== $a) {
99 $conditions[] = sprintf('(%s) mod %d = 0', $expr, $a); 99 $conditions[] = sprintf('(%s) mod %d = 0', $expr, $a);
100 } 100 }
101 101
148 public function translateContains(XPathExpr $xpath, FunctionNode $function) 148 public function translateContains(XPathExpr $xpath, FunctionNode $function)
149 { 149 {
150 $arguments = $function->getArguments(); 150 $arguments = $function->getArguments();
151 foreach ($arguments as $token) { 151 foreach ($arguments as $token) {
152 if (!($token->isString() || $token->isIdentifier())) { 152 if (!($token->isString() || $token->isIdentifier())) {
153 throw new ExpressionErrorException( 153 throw new ExpressionErrorException('Expected a single string or identifier for :contains(), got '.implode(', ', $arguments));
154 'Expected a single string or identifier for :contains(), got '
155 .implode(', ', $arguments)
156 );
157 } 154 }
158 } 155 }
159 156
160 return $xpath->addCondition(sprintf( 157 return $xpath->addCondition(sprintf(
161 'contains(string(.), %s)', 158 'contains(string(.), %s)',
171 public function translateLang(XPathExpr $xpath, FunctionNode $function) 168 public function translateLang(XPathExpr $xpath, FunctionNode $function)
172 { 169 {
173 $arguments = $function->getArguments(); 170 $arguments = $function->getArguments();
174 foreach ($arguments as $token) { 171 foreach ($arguments as $token) {
175 if (!($token->isString() || $token->isIdentifier())) { 172 if (!($token->isString() || $token->isIdentifier())) {
176 throw new ExpressionErrorException( 173 throw new ExpressionErrorException('Expected a single string or identifier for :lang(), got '.implode(', ', $arguments));
177 'Expected a single string or identifier for :lang(), got '
178 .implode(', ', $arguments)
179 );
180 } 174 }
181 } 175 }
182 176
183 return $xpath->addCondition(sprintf( 177 return $xpath->addCondition(sprintf(
184 'lang(%s)', 178 'lang(%s)',