SelectorMatcher

CSS selector compiler and matcher for the SVG cascade.

Namespace: Com\Tecnick\Pdf\CSS

class SelectorMatcher

Source: src/CSS/SelectorMatcher.php:61

CSS selector compiler and matcher for the SVG cascade.

Supports type, class, id and universal selectors, attribute selectors, the descendant, child, adjacent sibling and general sibling combinators, and the structural pseudo-classes that a document read in order can decide: ‘:root’, ‘:first-child’, ‘:nth-child()’, ‘:not()’ over a simple compound.

A selector that needs to look ahead of the current element (’:last-child’, ‘:only-child’, ‘:nth-last-child()’, ‘:empty’) or that uses anything else is rejected by compile(), so it applies to nothing rather than applying wrongly.

Types

TSelNode

array{
    'name': string,
    'id': string,
    'classes': array<int, string>,
    'attr': array<string, string>,
    'index': int,
    'depth': int,
}

TSelPart

array{
    'combinator': string,
    'type': string,
    'id': string,
    'classes': array<int, string>,
    'attrs': array<int, array{'name': string, 'op': string, 'value': string}>,
    'pseudo': array<int, array{'name': string, 'arg': string}>,
}

Methods

compile()

Compile a selector into the parts used by matches().

public static compile(string $selector): array<int,TSelPart>|null

Parameters:

  • $selector (string): Selector with its white space already collapsed.

Returns: array<int,TSelPart>|null: Compiled parts, or null when unsupported.

Source: src/CSS/SelectorMatcher.php:98

matches()

Return true when the last node of the chain matches the compiled selector.

public static matches(
    array<int,TSelPart> $parts,
    array<int,array{'node': TSelNode, 'prev': array<int,TSelNode>}> $chain
): bool

Parameters:

  • $parts (array<int,TSelPart>): Compiled selector.
  • $chain (array<int,array{’node’: TSelNode, ‘prev’: array<int,TSelNode>}>): Open elements from the root to the element under test.

Returns: bool

Source: src/CSS/SelectorMatcher.php:332