Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / symfony / css-selector / XPath / Extension / CombinationExtension.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
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 <jeanfrancois.simon@sensiolabs.com>
23  *
24  * @internal
25  */
26 class CombinationExtension extends AbstractExtension
27 {
28     /**
29      * {@inheritdoc}
30      */
31     public function getCombinationTranslators()
32     {
33         return array(
34             ' ' => array($this, 'translateDescendant'),
35             '>' => array($this, 'translateChild'),
36             '+' => array($this, 'translateDirectAdjacent'),
37             '~' => array($this, 'translateIndirectAdjacent'),
38         );
39     }
40
41     /**
42      * @return XPathExpr
43      */
44     public function translateDescendant(XPathExpr $xpath, XPathExpr $combinedXpath)
45     {
46         return $xpath->join('/descendant-or-self::*/', $combinedXpath);
47     }
48
49     /**
50      * @return XPathExpr
51      */
52     public function translateChild(XPathExpr $xpath, XPathExpr $combinedXpath)
53     {
54         return $xpath->join('/', $combinedXpath);
55     }
56
57     /**
58      * @return XPathExpr
59      */
60     public function translateDirectAdjacent(XPathExpr $xpath, XPathExpr $combinedXpath)
61     {
62         return $xpath
63             ->join('/following-sibling::', $combinedXpath)
64             ->addNameTest()
65             ->addCondition('position() = 1');
66     }
67
68     /**
69      * @return XPathExpr
70      */
71     public function translateIndirectAdjacent(XPathExpr $xpath, XPathExpr $combinedXpath)
72     {
73         return $xpath->join('/following-sibling::', $combinedXpath);
74     }
75
76     /**
77      * {@inheritdoc}
78      */
79     public function getName()
80     {
81         return 'combination';
82     }
83 }