PHP Class QueryPath\CSS\DOMTraverser

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: - First, find all baz elements. - Next, for any baz element that does not have foo as an ancestor, eliminate it from the matches. - Finally, for those that have foo as an ancestor, does that foo also have a class baz? If not, it is removed from the matches. \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).
Inheritance: implements QueryPath\CSS\Traverser
Mostrar archivo Open project: microweber/microweber Class Usage Examples

Protected Properties

Property Type Description
$dom
$initialized
$matches
$psHandler
$scopeNode
$selector

Public Methods

Method Description
__construct ( SPLObjectStorage $splos, $initialized = false, $scopeNode = null ) Build a new DOMTraverser.
attachNodeList ( DOMNodeList $nodeList, SplObjectStorage $splos ) Attach all nodes in a node list to the given \SplObjectStorage.
combine ( DOMNode $node, array $selectors, integer $index ) Combine the next selector with the given match using the next combinator.
combineAdjacent ( DOMNode $node, array $selectors, integer $index ) : boolean Process an Adjacent Sibling.
combineAnyDescendant ( DOMNode $node, array $selectors, integer $index ) : boolean Handle Any Descendant combinations.
combineDirectDescendant ( DOMNode $node, array $selectors, integer $index ) : boolean Handle a Direct Descendant combination.
combineSibling ( DOMNode $node, array $selectors, integer $index ) : boolean Check all siblings.
debug ( $msg )
find ( string $selector ) Given a selector, find the matches in the given DOM.
getDocument ( )
matches ( )
matchesSelector ( $node, $selector ) Check whether the given node matches the given selector.
matchesSimpleSelector ( $node, $selectors, $index ) Performs a match check on a SimpleSelector.

Protected Methods

Method Description
ancestors ( $node ) Get a list of ancestors to the present node.
getMatches ( ) Get the internal match set.
initialMatch ( $selector, $matches ) Get the intial match set.
initialMatchOnClasses ( $selector, $matches ) Shortcut for setting the intial match.
initialMatchOnElement ( $selector, $matches ) Shortcut for setting the initial match.
initialMatchOnElementNS ( $selector, $matches ) Get elements and filter by namespace.
initialMatchOnID ( $selector, $matches ) Shortcut for finding initial match by ID.
matchAttributes ( $node, $attributes ) Check to see if DOMNode has all of the given attributes.
matchClasses ( $node, $classes ) Check that the given DOMNode has all of the given classes.
matchElement ( $node, $element, $ns = null ) Checks to see if the DOMNode matches the given element selector.
matchId ( $node, $id ) Check that the given DOMNode has the given ID.
matchPseudoClasses ( $node, $pseudoClasses )
matchPseudoElements ( $node, $pseudoElements ) Test whether the given node matches the pseudoElements.
newMatches ( )
setMatches ( $matches ) Set the internal match set.

Private Methods

Method Description
initialXpathQuery ( $xpath, $node, $query ) Internal xpath query.

Method Details

__construct() public method

This requires a DOM-like object or collection of DOM nodes.
public __construct ( SPLObjectStorage $splos, $initialized = false, $scopeNode = null )
$splos SPLObjectStorage

ancestors() protected method

Get a list of ancestors to the present node.
protected ancestors ( $node )

attachNodeList() public method

Attach all nodes in a node list to the given \SplObjectStorage.
public attachNodeList ( DOMNodeList $nodeList, SplObjectStorage $splos )
$nodeList DOMNodeList
$splos SplObjectStorage

combine() public method

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.
public combine ( DOMNode $node, array $selectors, integer $index )
$node DOMNode The DOMNode to test.
$selectors array The array of simple selectors.
$index integer The index of the current selector.

combineAdjacent() public method

The spec does not indicate whether Adjacent should ignore non-Element nodes, so we choose to ignore them.
public combineAdjacent ( DOMNode $node, array $selectors, integer $index ) : boolean
$node DOMNode A DOM Node.
$selectors array The selectors array.
$index integer The current index to the operative simple selector in the selectors array.
return boolean TRUE if the combination matches, FALSE otherwise.

combineAnyDescendant() public method

This checks to see if there are any matching routes from the selector beginning at the present node.
public combineAnyDescendant ( DOMNode $node, array $selectors, integer $index ) : boolean
$node DOMNode A DOM Node.
$selectors array The selectors array.
$index integer The current index to the operative simple selector in the selectors array.
return boolean TRUE if the combination matches, FALSE otherwise.

combineDirectDescendant() public method

Check whether the given node is a rightly-related descendant of its parent node.
public combineDirectDescendant ( DOMNode $node, array $selectors, integer $index ) : boolean
$node DOMNode A DOM Node.
$selectors array The selectors array.
$index integer The current index to the operative simple selector in the selectors array.
return boolean TRUE if the combination matches, FALSE otherwise.

combineSibling() public method

According to the spec, this only tests elements LEFT of the provided node.
public combineSibling ( DOMNode $node, array $selectors, integer $index ) : boolean
$node DOMNode A DOM Node.
$selectors array The selectors array.
$index integer The current index to the operative simple selector in the selectors array.
return boolean TRUE if the combination matches, FALSE otherwise.

debug() public method

public debug ( $msg )

find() public method

This is the main function for querying the DOM using a CSS selector.
public find ( string $selector )
$selector string The selector.

getDocument() public method

public getDocument ( )

getMatches() protected method

Internal utility function.
protected getMatches ( )

initialMatch() protected method

This should only be executed when not working with an existing match set.
protected initialMatch ( $selector, $matches )

initialMatchOnClasses() protected method

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.
protected initialMatchOnClasses ( $selector, $matches )

initialMatchOnElement() protected method

Shortcut for setting the initial match.
protected initialMatchOnElement ( $selector, $matches )

initialMatchOnElementNS() protected method

Get elements and filter by namespace.
protected initialMatchOnElementNS ( $selector, $matches )

initialMatchOnID() protected method

If the element is set to '*' and an ID is set, then this should be used to find by ID, which will drastically reduce the amount of comparison operations done in PHP.
protected initialMatchOnID ( $selector, $matches )

matchAttributes() protected method

This can handle namespaced attributes, including namespace wildcards.
protected matchAttributes ( $node, $attributes )

matchClasses() protected method

Check that the given DOMNode has all of the given classes.
protected matchClasses ( $node, $classes )

matchElement() protected method

This handles the following cases: - element (foo) - namespaced element (ns|foo) - namespaced wildcard (ns|*) - wildcard (* or *|*)
protected matchElement ( $node, $element, $ns = null )

matchId() protected method

Check that the given DOMNode has the given ID.
protected matchId ( $node, $id )

matchPseudoClasses() protected method

protected matchPseudoClasses ( $node, $pseudoClasses )

matchPseudoElements() protected method

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.
protected matchPseudoElements ( $node, $pseudoElements )

matches() public method

public matches ( )

matchesSelector() public method

A selector is a group of one or more simple selectors combined by combinators. This determines if a given selector matches the given node.
public matchesSelector ( $node, $selector )

matchesSimpleSelector() public method

Where matchesSelector() does a check on an entire selector, this checks only a simple selector (plus an optional combinator).
public matchesSimpleSelector ( $node, $selectors, $index )

newMatches() protected method

protected newMatches ( )

setMatches() protected method

Internal utility function.
protected setMatches ( $matches )

Property Details

$dom protected_oe property

protected $dom

$initialized protected_oe property

protected $initialized

$matches protected_oe property

protected $matches

$psHandler protected_oe property

protected $psHandler

$scopeNode protected_oe property

protected $scopeNode

$selector protected_oe property

protected $selector