Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. XPathExpr.php

class XPathExpr

XPath expression translator interface.

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

@internal

Hierarchy

  • class \Symfony\Component\CssSelector\XPath\XPathExpr

Expanded class hierarchy of XPathExpr

See also

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

6 files declare their use of XPathExpr
AttributeMatchingExtension.php in vendor/symfony/css-selector/XPath/Extension/AttributeMatchingExtension.php
CombinationExtension.php in vendor/symfony/css-selector/XPath/Extension/CombinationExtension.php
FunctionExtension.php in vendor/symfony/css-selector/XPath/Extension/FunctionExtension.php
HtmlExtension.php in vendor/symfony/css-selector/XPath/Extension/HtmlExtension.php
NodeExtension.php in vendor/symfony/css-selector/XPath/Extension/NodeExtension.php

... See full list

File

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

Namespace

Symfony\Component\CssSelector\XPath
View source
class XPathExpr {
    public function __construct(string $path = '', string $element = '*', string $condition = '', bool $starPrefix = false) {
        if ($starPrefix) {
            $this->addStarPrefix();
        }
    }
    public function getElement() : string {
        return $this->element;
    }
    
    /**
     * @return $this
     */
    public function addCondition(string $condition, string $operator = 'and') : static {
        $this->condition = $this->condition ? \sprintf('(%s) %s (%s)', $this->condition, $operator, $condition) : $condition;
        return $this;
    }
    public function getCondition() : string {
        return $this->condition;
    }
    
    /**
     * @return $this
     */
    public function addNameTest() : static {
        if ('*' !== $this->element) {
            $this->addCondition('name() = ' . Translator::getXpathLiteral($this->element));
            $this->element = '*';
        }
        return $this;
    }
    
    /**
     * @return $this
     */
    public function addStarPrefix() : static {
        $this->path .= '*/';
        return $this;
    }
    
    /**
     * Joins another XPathExpr with a combiner.
     *
     * @return $this
     */
    public function join(string $combiner, self $expr) : static {
        $path = $this->__toString() . $combiner;
        if ('*/' !== $expr->path) {
            $path .= $expr->path;
        }
        $this->path = $path;
        $this->element = $expr->element;
        $this->condition = $expr->condition;
        return $this;
    }
    public function __toString() : string {
        $path = $this->path . $this->element;
        $condition = '' === $this->condition ? '' : '[' . $this->condition . ']';
        return $path . $condition;
    }

}

Members

Title Sort descending Modifiers Object type Summary
XPathExpr::addCondition public function
XPathExpr::addNameTest public function
XPathExpr::addStarPrefix public function
XPathExpr::getCondition public function
XPathExpr::getElement public function
XPathExpr::join public function Joins another XPathExpr with a combiner.
XPathExpr::__construct public function
XPathExpr::__toString public function
RSS feed
Powered by Drupal