You are here

class CombinationExtension in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/css-selector/XPath/Extension/CombinationExtension.php \Symfony\Component\CssSelector\XPath\Extension\CombinationExtension

XPath expression translator combination extension.

This component is a port of the Python cssselect library, which is copyright Ian Bicking, @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com>

Hierarchy

Expanded class hierarchy of CombinationExtension

See also

https://github.com/SimonSapin/cssselect.

File

vendor/symfony/css-selector/XPath/Extension/CombinationExtension.php, line 24

Namespace

Symfony\Component\CssSelector\XPath\Extension
View source
class CombinationExtension extends AbstractExtension {

  /**
   * {@inheritdoc}
   */
  public function getCombinationTranslators() {
    return array(
      ' ' => array(
        $this,
        'translateDescendant',
      ),
      '>' => array(
        $this,
        'translateChild',
      ),
      '+' => array(
        $this,
        'translateDirectAdjacent',
      ),
      '~' => array(
        $this,
        'translateIndirectAdjacent',
      ),
    );
  }

  /**
   * @param XPathExpr $xpath
   * @param XPathExpr $combinedXpath
   *
   * @return XPathExpr
   */
  public function translateDescendant(XPathExpr $xpath, XPathExpr $combinedXpath) {
    return $xpath
      ->join('/descendant-or-self::*/', $combinedXpath);
  }

  /**
   * @param XPathExpr $xpath
   * @param XPathExpr $combinedXpath
   *
   * @return XPathExpr
   */
  public function translateChild(XPathExpr $xpath, XPathExpr $combinedXpath) {
    return $xpath
      ->join('/', $combinedXpath);
  }

  /**
   * @param XPathExpr $xpath
   * @param XPathExpr $combinedXpath
   *
   * @return XPathExpr
   */
  public function translateDirectAdjacent(XPathExpr $xpath, XPathExpr $combinedXpath) {
    return $xpath
      ->join('/following-sibling::', $combinedXpath)
      ->addNameTest()
      ->addCondition('position() = 1');
  }

  /**
   * @param XPathExpr $xpath
   * @param XPathExpr $combinedXpath
   *
   * @return XPathExpr
   */
  public function translateIndirectAdjacent(XPathExpr $xpath, XPathExpr $combinedXpath) {
    return $xpath
      ->join('/following-sibling::', $combinedXpath);
  }

  /**
   * {@inheritdoc}
   */
  public function getName() {
    return 'combination';
  }

}

Members