Merge pull request #4036 from dokuwiki/issue4033
[dokuwiki.git] / _test / vendor / symfony / css-selector / XPath / Extension / CombinationExtension.php
blobaee976e9493efac4142bceca37a4f42d27e30bb9
1 <?php
3 /*
4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\CssSelector\XPath\Extension;
14 use Symfony\Component\CssSelector\XPath\XPathExpr;
16 /**
17 * XPath expression translator combination extension.
19 * This component is a port of the Python cssselect library,
20 * which is copyright Ian Bicking, @see https://github.com/SimonSapin/cssselect.
22 * @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com>
24 * @internal
26 class CombinationExtension extends AbstractExtension
28 /**
29 * {@inheritdoc}
31 public function getCombinationTranslators(): array
33 return [
34 ' ' => [$this, 'translateDescendant'],
35 '>' => [$this, 'translateChild'],
36 '+' => [$this, 'translateDirectAdjacent'],
37 '~' => [$this, 'translateIndirectAdjacent'],
41 public function translateDescendant(XPathExpr $xpath, XPathExpr $combinedXpath): XPathExpr
43 return $xpath->join('/descendant-or-self::*/', $combinedXpath);
46 public function translateChild(XPathExpr $xpath, XPathExpr $combinedXpath): XPathExpr
48 return $xpath->join('/', $combinedXpath);
51 public function translateDirectAdjacent(XPathExpr $xpath, XPathExpr $combinedXpath): XPathExpr
53 return $xpath
54 ->join('/following-sibling::', $combinedXpath)
55 ->addNameTest()
56 ->addCondition('position() = 1');
59 public function translateIndirectAdjacent(XPathExpr $xpath, XPathExpr $combinedXpath): XPathExpr
61 return $xpath->join('/following-sibling::', $combinedXpath);
64 /**
65 * {@inheritdoc}
67 public function getName(): string
69 return 'combination';