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;
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>
26 class CombinationExtension extends AbstractExtension
31 public function getCombinationTranslators()
34 ' ' => array($this, 'translateDescendant'),
35 '>' => array($this, 'translateChild'),
36 '+' => array($this, 'translateDirectAdjacent'),
37 '~' => array($this, 'translateIndirectAdjacent'),
42 * @param XPathExpr $xpath
43 * @param XPathExpr $combinedXpath
47 public function translateDescendant(XPathExpr $xpath, XPathExpr $combinedXpath)
49 return $xpath->join('/descendant-or-self::*/', $combinedXpath);
53 * @param XPathExpr $xpath
54 * @param XPathExpr $combinedXpath
58 public function translateChild(XPathExpr $xpath, XPathExpr $combinedXpath)
60 return $xpath->join('/', $combinedXpath);
64 * @param XPathExpr $xpath
65 * @param XPathExpr $combinedXpath
69 public function translateDirectAdjacent(XPathExpr $xpath, XPathExpr $combinedXpath)
72 ->join('/following-sibling::', $combinedXpath)
74 ->addCondition('position() = 1');
78 * @param XPathExpr $xpath
79 * @param XPathExpr $combinedXpath
83 public function translateIndirectAdjacent(XPathExpr $xpath, XPathExpr $combinedXpath)
85 return $xpath->join('/following-sibling::', $combinedXpath);
91 public function getName()