PHP Класс 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).
Наследование: implements QueryPath\CSS\Traverser
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$dom
$initialized
$matches
$psHandler
$scopeNode
$selector

Открытые методы

Метод Описание
__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.

Защищенные методы

Метод Описание
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.

Приватные методы

Метод Описание
initialXpathQuery ( $xpath, $node, $query ) Internal xpath query.

Описание методов

__construct() публичный Метод

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

ancestors() защищенный Метод

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

attachNodeList() публичный Метод

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

combine() публичный Метод

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() публичный Метод

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.
Результат boolean TRUE if the combination matches, FALSE otherwise.

combineAnyDescendant() публичный Метод

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.
Результат boolean TRUE if the combination matches, FALSE otherwise.

combineDirectDescendant() публичный Метод

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.
Результат boolean TRUE if the combination matches, FALSE otherwise.

combineSibling() публичный Метод

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.
Результат boolean TRUE if the combination matches, FALSE otherwise.

debug() публичный Метод

public debug ( $msg )

find() публичный Метод

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

getDocument() публичный Метод

public getDocument ( )

getMatches() защищенный Метод

Internal utility function.
protected getMatches ( )

initialMatch() защищенный Метод

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

initialMatchOnClasses() защищенный Метод

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() защищенный Метод

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

initialMatchOnElementNS() защищенный Метод

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

initialMatchOnID() защищенный Метод

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() защищенный Метод

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

matchClasses() защищенный Метод

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

matchElement() защищенный Метод

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

matchId() защищенный Метод

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

matchPseudoClasses() защищенный Метод

protected matchPseudoClasses ( $node, $pseudoClasses )

matchPseudoElements() защищенный Метод

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 matches ( )

matchesSelector() публичный Метод

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() публичный Метод

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 newMatches ( )

setMatches() защищенный Метод

Internal utility function.
protected setMatches ( $matches )

Описание свойств

$dom защищенное свойство

protected $dom

$initialized защищенное свойство

protected $initialized

$matches защищенное свойство

protected $matches

$psHandler защищенное свойство

protected $psHandler

$scopeNode защищенное свойство

protected $scopeNode

$selector защищенное свойство

protected $selector