Automattic\WooCommerce\EmailEditorVendor\Symfony\Component\CssSelector

CssSelectorConverter::toXPath │ public │ WC 1.0

Translates a CSS expression to its XPath equivalent.

Optionally, a prefix can be added to the resulting XPath expression with the $prefix parameter.

Method of the class: CssSelectorConverter{}

No Hooks.

Returns

string.

Usage

$CssSelectorConverter = new CssSelectorConverter();
$CssSelectorConverter->toXPath( $cssExpr, $prefix );
$cssExpr(string) (required)
.
$prefix(string)
.
Default: 'descendant-or-self::'

CssSelectorConverter::toXPath() code WC 11.3.0

public function toXPath(string $cssExpr, string $prefix = 'descendant-or-self::')
{
    if (isset($this->cache[$prefix][$cssExpr])) {
        // Promote to most-recently-used position.
        $value = $this->cache[$prefix][$cssExpr];
        unset($this->cache[$prefix][$cssExpr]);

        return $this->cache[$prefix][$cssExpr] = $value;
    }

    $value = $this->translator->cssToXPath($cssExpr, $prefix);

    if (\count($this->cache[$prefix] ?? []) >= self::$maxCachedItems) {
        // Evict least-recently-used entry.
        unset($this->cache[$prefix][\array_key_first($this->cache[$prefix])]);
    }

    return $this->cache[$prefix][$cssExpr] = $value;
}