$matches
$matches :
Traverse a DOM, finding matches to the selector.
This traverses a DOMDocument and attempts to find matches to the provided selector.
\b How this works
This performs a bottom-up search. On the first pass, it attempts to find all of the matching elements for the last simple selector in a selector.
Subsequent passes attempt to eliminate matches from the initial matching set.
Example:
Say we begin with the selector foo.bar baz
. This is processed
as follows:
\b Extrapolation
Partial simple selectors are almost always expanded to include an element.
Examples:
:first
is expanded to *:first
.bar
is expanded to *.bar
..outer .inner
is expanded to *.outer *.inner
The exception is that IDs are sometimes not expanded, e.g.:
#myElement
does not get expanded#myElement .class
\i may be expanded to *#myElement *.class
(which will obviously not perform well).find(string $selector) : \SPLObjectStorage
Given a selector, find the matches in the given DOM.
This is the main function for querying the DOM using a CSS selector.
string | $selector | The selector. |
An SPLObjectStorage containing a list of matched DOMNode objects.
matches() : array
Get the results of a find() operation.
Return an array of matching items.
An array of matched values. The specific data type in the matches will differ depending on the data type searched, but in the core QueryPath implementation, this will be an array of DOMNode objects.
matchesSelector( $node, $selector) : boolean
Check whether the given node matches the given selector.
A selector is a group of one or more simple selectors combined by combinators. This determines if a given selector matches the given node.
$node | ||
$selector |
A boolean TRUE if the node matches, false otherwise.
matchesSimpleSelector( $node, $selectors, $index) : boolean
Performs a match check on a SimpleSelector.
Where matchesSelector() does a check on an entire selector, this checks only a simple selector (plus an optional combinator).
$node | ||
$selectors | ||
$index |
A boolean TRUE if the node matches, false otherwise.
combine(\QueryPath\CSS\DOMNode $node, array $selectors, integer $index) : boolean
Combine the next selector with the given match using the next combinator.
If the next selector is combined with another selector, that will be evaluated too, and so on. So if this function returns TRUE, it means that all child selectors are also matches.
\QueryPath\CSS\DOMNode | $node | The DOMNode to test. |
array | $selectors | The array of simple selectors. |
integer | $index | The index of the current selector. |
TRUE if the next selector(s) match.
combineAdjacent(\QueryPath\CSS\DOMNode $node, array $selectors, integer $index) : boolean
Process an Adjacent Sibling.
The spec does not indicate whether Adjacent should ignore non-Element nodes, so we choose to ignore them.
\QueryPath\CSS\DOMNode | $node | A DOM Node. |
array | $selectors | The selectors array. |
integer | $index | The current index to the operative simple selector in the selectors array. |
TRUE if the combination matches, FALSE otherwise.
combineSibling(\QueryPath\CSS\DOMNode $node, array $selectors, integer $index) : boolean
Check all siblings.
According to the spec, this only tests elements LEFT of the provided node.
\QueryPath\CSS\DOMNode | $node | A DOM Node. |
array | $selectors | The selectors array. |
integer | $index | The current index to the operative simple selector in the selectors array. |
TRUE if the combination matches, FALSE otherwise.
combineDirectDescendant(\QueryPath\CSS\DOMNode $node, array $selectors, integer $index) : boolean
Handle a Direct Descendant combination.
Check whether the given node is a rightly-related descendant of its parent node.
\QueryPath\CSS\DOMNode | $node | A DOM Node. |
array | $selectors | The selectors array. |
integer | $index | The current index to the operative simple selector in the selectors array. |
TRUE if the combination matches, FALSE otherwise.
combineAnyDescendant(\QueryPath\CSS\DOMNode $node, array $selectors, integer $index) : boolean
Handle Any Descendant combinations.
This checks to see if there are any matching routes from the selector beginning at the present node.
\QueryPath\CSS\DOMNode | $node | A DOM Node. |
array | $selectors | The selectors array. |
integer | $index | The current index to the operative simple selector in the selectors array. |
TRUE if the combination matches, FALSE otherwise.
initialMatchOnClasses( $selector, $matches)
Shortcut for setting the intial match.
This shortcut should only be used when the initial element is '*' and there are classes set.
In any other case, the element finding algo is faster and should be used instead.
$selector | ||
$matches |
matchPseudoElements( $node, $pseudoElements)
Test whether the given node matches the pseudoElements.
If any pseudo-elements are passed, this will test to see if conditions obtain that would allow the pseudo-element to be created. This does not modify the match in any way.
$node | ||
$pseudoElements |