Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/css-selector/XPath/Translator.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 private $mainParser; | 33 private $mainParser; |
34 | 34 |
35 /** | 35 /** |
36 * @var ParserInterface[] | 36 * @var ParserInterface[] |
37 */ | 37 */ |
38 private $shortcutParsers = array(); | 38 private $shortcutParsers = []; |
39 | 39 |
40 /** | 40 /** |
41 * @var Extension\ExtensionInterface[] | 41 * @var Extension\ExtensionInterface[] |
42 */ | 42 */ |
43 private $extensions = array(); | 43 private $extensions = []; |
44 | 44 |
45 private $nodeTranslators = array(); | 45 private $nodeTranslators = []; |
46 private $combinationTranslators = array(); | 46 private $combinationTranslators = []; |
47 private $functionTranslators = array(); | 47 private $functionTranslators = []; |
48 private $pseudoClassTranslators = array(); | 48 private $pseudoClassTranslators = []; |
49 private $attributeMatchingTranslators = array(); | 49 private $attributeMatchingTranslators = []; |
50 | 50 |
51 public function __construct(ParserInterface $parser = null) | 51 public function __construct(ParserInterface $parser = null) |
52 { | 52 { |
53 $this->mainParser = $parser ?: new Parser(); | 53 $this->mainParser = $parser ?: new Parser(); |
54 | 54 |
75 if (false === strpos($element, '"')) { | 75 if (false === strpos($element, '"')) { |
76 return '"'.$element.'"'; | 76 return '"'.$element.'"'; |
77 } | 77 } |
78 | 78 |
79 $string = $element; | 79 $string = $element; |
80 $parts = array(); | 80 $parts = []; |
81 while (true) { | 81 while (true) { |
82 if (false !== $pos = strpos($string, "'")) { | 82 if (false !== $pos = strpos($string, "'")) { |
83 $parts[] = sprintf("'%s'", substr($string, 0, $pos)); | 83 $parts[] = sprintf("'%s'", substr($string, 0, $pos)); |
84 $parts[] = "\"'\""; | 84 $parts[] = "\"'\""; |
85 $string = substr($string, $pos + 1); | 85 $string = substr($string, $pos + 1); |
87 $parts[] = "'$string'"; | 87 $parts[] = "'$string'"; |
88 break; | 88 break; |
89 } | 89 } |
90 } | 90 } |
91 | 91 |
92 return sprintf('concat(%s)', implode($parts, ', ')); | 92 return sprintf('concat(%s)', implode(', ', $parts)); |
93 } | 93 } |
94 | 94 |
95 /** | 95 /** |
96 * {@inheritdoc} | 96 * {@inheritdoc} |
97 */ | 97 */ |
174 { | 174 { |
175 if (!isset($this->nodeTranslators[$node->getNodeName()])) { | 175 if (!isset($this->nodeTranslators[$node->getNodeName()])) { |
176 throw new ExpressionErrorException(sprintf('Node "%s" not supported.', $node->getNodeName())); | 176 throw new ExpressionErrorException(sprintf('Node "%s" not supported.', $node->getNodeName())); |
177 } | 177 } |
178 | 178 |
179 return call_user_func($this->nodeTranslators[$node->getNodeName()], $node, $this); | 179 return \call_user_func($this->nodeTranslators[$node->getNodeName()], $node, $this); |
180 } | 180 } |
181 | 181 |
182 /** | 182 /** |
183 * @param string $combiner | 183 * @param string $combiner |
184 * @param NodeInterface $xpath | 184 * @param NodeInterface $xpath |
192 { | 192 { |
193 if (!isset($this->combinationTranslators[$combiner])) { | 193 if (!isset($this->combinationTranslators[$combiner])) { |
194 throw new ExpressionErrorException(sprintf('Combiner "%s" not supported.', $combiner)); | 194 throw new ExpressionErrorException(sprintf('Combiner "%s" not supported.', $combiner)); |
195 } | 195 } |
196 | 196 |
197 return call_user_func($this->combinationTranslators[$combiner], $this->nodeToXPath($xpath), $this->nodeToXPath($combinedXpath)); | 197 return \call_user_func($this->combinationTranslators[$combiner], $this->nodeToXPath($xpath), $this->nodeToXPath($combinedXpath)); |
198 } | 198 } |
199 | 199 |
200 /** | 200 /** |
201 * @return XPathExpr | 201 * @return XPathExpr |
202 * | 202 * |
206 { | 206 { |
207 if (!isset($this->functionTranslators[$function->getName()])) { | 207 if (!isset($this->functionTranslators[$function->getName()])) { |
208 throw new ExpressionErrorException(sprintf('Function "%s" not supported.', $function->getName())); | 208 throw new ExpressionErrorException(sprintf('Function "%s" not supported.', $function->getName())); |
209 } | 209 } |
210 | 210 |
211 return call_user_func($this->functionTranslators[$function->getName()], $xpath, $function); | 211 return \call_user_func($this->functionTranslators[$function->getName()], $xpath, $function); |
212 } | 212 } |
213 | 213 |
214 /** | 214 /** |
215 * @param XPathExpr $xpath | 215 * @param XPathExpr $xpath |
216 * @param string $pseudoClass | 216 * @param string $pseudoClass |
223 { | 223 { |
224 if (!isset($this->pseudoClassTranslators[$pseudoClass])) { | 224 if (!isset($this->pseudoClassTranslators[$pseudoClass])) { |
225 throw new ExpressionErrorException(sprintf('Pseudo-class "%s" not supported.', $pseudoClass)); | 225 throw new ExpressionErrorException(sprintf('Pseudo-class "%s" not supported.', $pseudoClass)); |
226 } | 226 } |
227 | 227 |
228 return call_user_func($this->pseudoClassTranslators[$pseudoClass], $xpath); | 228 return \call_user_func($this->pseudoClassTranslators[$pseudoClass], $xpath); |
229 } | 229 } |
230 | 230 |
231 /** | 231 /** |
232 * @param XPathExpr $xpath | 232 * @param XPathExpr $xpath |
233 * @param string $operator | 233 * @param string $operator |
242 { | 242 { |
243 if (!isset($this->attributeMatchingTranslators[$operator])) { | 243 if (!isset($this->attributeMatchingTranslators[$operator])) { |
244 throw new ExpressionErrorException(sprintf('Attribute matcher operator "%s" not supported.', $operator)); | 244 throw new ExpressionErrorException(sprintf('Attribute matcher operator "%s" not supported.', $operator)); |
245 } | 245 } |
246 | 246 |
247 return call_user_func($this->attributeMatchingTranslators[$operator], $xpath, $attribute, $value); | 247 return \call_user_func($this->attributeMatchingTranslators[$operator], $xpath, $attribute, $value); |
248 } | 248 } |
249 | 249 |
250 /** | 250 /** |
251 * @param string $css | 251 * @param string $css |
252 * | 252 * |