PluginProbe
BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript / 4.1.17
BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript v4.1.17
4.1.19 4.1.18 4.1.17 4.1.16 4.1.15 4.1.14 4.1.13 4.1.12 4.1.11 4.1.10 4.0.30 4.0.29 4.0.28 4.0.27 4.0.26 4.0.24 4.0.25 4.0.23 4.0.22 4.0.21 4.0.19 4.0.18 4.0.17 4.0.16 1.9.3 All 173 releases
searchpro / BerqWP / vendor / symfony / css-selector / XPath / Extension / CombinationExtension.php

CombinationExtension.php in BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript 4.1.17, at BerqWP/vendor/symfony/css-selector/XPath/Extension/CombinationExtension.php

72 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <[email protected]>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Symfony\Component\CssSelector\XPath\Extension;
13
14 use Symfony\Component\CssSelector\XPath\XPathExpr;
15
16 /**
17 * XPath expression translator combination extension.
18 *
19 * This component is a port of the Python cssselect library,
20 * which is copyright Ian Bicking, @see https://github.com/SimonSapin/cssselect.
21 *
22 * @author Jean-François Simon <[email protected]>
23 *
24 * @internal
25 */
26 class CombinationExtension extends AbstractExtension
27 {
28 /**
29 * {@inheritdoc}
30 */
31 public function getCombinationTranslators(): array
32 {
33 return [
34 ' ' => [$this, 'translateDescendant'],
35 '>' => [$this, 'translateChild'],
36 '+' => [$this, 'translateDirectAdjacent'],
37 '~' => [$this, 'translateIndirectAdjacent'],
38 ];
39 }
40
41 public function translateDescendant(XPathExpr $xpath, XPathExpr $combinedXpath): XPathExpr
42 {
43 return $xpath->join('/descendant-or-self::*/', $combinedXpath);
44 }
45
46 public function translateChild(XPathExpr $xpath, XPathExpr $combinedXpath): XPathExpr
47 {
48 return $xpath->join('/', $combinedXpath);
49 }
50
51 public function translateDirectAdjacent(XPathExpr $xpath, XPathExpr $combinedXpath): XPathExpr
52 {
53 return $xpath
54 ->join('/following-sibling::', $combinedXpath)
55 ->addNameTest()
56 ->addCondition('position() = 1');
57 }
58
59 public function translateIndirectAdjacent(XPathExpr $xpath, XPathExpr $combinedXpath): XPathExpr
60 {
61 return $xpath->join('/following-sibling::', $combinedXpath);
62 }
63
64 /**
65 * {@inheritdoc}
66 */
67 public function getName(): string
68 {
69 return 'combination';
70 }
71 }
72