PHP Класс QueryPath\CSS\QueryPathEventHandler

The main idea is that we keep a copy of the tree, and then use an array to keep track of matches. To handle a list of selectors (using the comma separator), we have to track both the currently progressing match and the previously matched elements. To use this handler:
Наследование: implements QueryPath\CSS\EventHandler, implements QueryPath\CSS\Traverser
Показать файл Открыть проект Примеры использования класса

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

Свойство Тип Описание
$alreadyMatched The matches
$dom
$findAnyElement Matches found before current selector.
$matches Always points to the top level.

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

Метод Описание
__construct ( $dom ) Create a new event handler.
adjacent ( ) For an element to be adjacent to another, it must be THE NEXT NODE in the node list. So if an element is surrounded by pcdata, there are no adjacent nodes. E.g. in FOO, the a and b elements are not adjacent.
anotherSelector ( )
anyDescendant ( ) Get any descendant.
anyElement ( )
anyElementInNS ( $ns )
attachNodeList ( DOMNodeList $nodeList, SplObjectStorage $splos ) Attach all nodes in a node list to the given \SplObjectStorage.
attribute ( $name, $value = null, $operation = EventHandler::isExactly )
attributeNS ( $lname, $ns, $value = null, $operation = EventHandler::isExactly )
directDescendant ( )
element ( $name ) Inherited
elementClass ( $name )
elementID ( $id ) Find any element with the ID that matches $id.
elementNS ( $lname, $namespace = null ) Inherited
find ( string $filter ) : QueryPathEventHandler Generic finding method.
getMatches ( ) : array Get the elements that match the evaluated selector.
has ( $filter ) Pseudo-class handler for :has(filter).
matches ( )
pseudoClass ( $name, $value = null ) This also supports the following nonstandard pseudo classes: - :x-reset/:x-root (reset to the main item passed into the constructor. Less drastic than :root) - :odd/:even (shorthand for :nth-child(odd)/:nth-child(even)).
pseudoElement ( $name ) As the spec mentions, these must be at the end of a selector or else they will cause errors. Most selectors return elements. Pseudo-elements do not.
sibling ( ) Get all nodes that are siblings to currently selected nodes.

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

Метод Описание
attrValMatches ( $needle, $haystack, $operation ) Check for attr value matches based on an operation.
emptyElement ( ) Pseudo-class handler for :empty.
firstOfType ( ) Pseudo-class handler for :first-of-type.
lang ( $value ) Pseudo-class handler for :lang.
lastOfType ( ) Pseudo-class handler for :last-of-type.
not ( string $filter ) Pseudo-class handler for :not(filter).
nthChild ( integer $groupSize, integer $elementInGroup, boolean $lastChild = false ) Pseudo-class handler for nth-child and all related pseudo-classes.
nthLastChild ( $groupSize, $elementInGroup ) Pseudo-class handler for :nth-last-child and related pseudo-classes.
nthLastOfTypeChild ( $groupSize, $elementInGroup ) Pseudo-class handler for nth-last-of-type-child.
nthOfTypeChild ( $groupSize, $elementInGroup, $lastChild ) Pseudo-class handler for nth-of-type-child.
onlyChild ( ) Pseudo-class handler for :only-child.
onlyOfType ( ) Pseudo-class handler for :only-of-type.
parseAnB ( $rule ) Parse an an+b rule for CSS pseudo-classes.
searchForAttr ( $name, $value = null ) Helper function to find all elements with exact matches.

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

Метод Описание
candidateList ( ) Determine what candidates are in the current scope.
getAllCandidates ( $elements ) Get a list of all of the candidate elements.
getByPosition ( $operator, $pos ) Pseudo-class handler for a variety of jQuery pseudo-classes.
removeQuotes ( $str ) Remove leading and trailing quotes.

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

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

Create a new event handler.
public __construct ( $dom )

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

In a strict DOM parser, line breaks and empty spaces are nodes. That means nodes like this will not be adjacent: . The space between them makes them non-adjacent. If this is not the desired behavior, pass in the appropriate flags to your parser. Example: $doc = new DomDocument(); $doc->loadXML(' ', LIBXML_NOBLANKS);
public adjacent ( )

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

public anotherSelector ( )

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

Get any descendant.
public anyDescendant ( )

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

public anyElement ( )

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

public anyElementInNS ( $ns )

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

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

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

Check for attr value matches based on an operation.
protected attrValMatches ( $needle, $haystack, $operation )

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

public attribute ( $name, $value = null, $operation = EventHandler::isExactly )

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

public attributeNS ( $lname, $ns, $value = null, $operation = EventHandler::isExactly )

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

public directDescendant ( )

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

Inherited
public element ( $name )

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

public elementClass ( $name )

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

If this finds an ID, it will immediately quit. Essentially, it doesn't enforce ID uniqueness, but it assumes it.
public elementID ( $id )
$id String ID for an element.

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

Inherited
public elementNS ( $lname, $namespace = null )

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

Pseudo-class handler for :empty.
protected emptyElement ( )

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

This is the primary searching method used throughout QueryPath.
public find ( string $filter ) : QueryPathEventHandler
$filter string A valid CSS 3 filter.
Результат QueryPathEventHandler Returns itself.

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

Pseudo-class handler for :first-of-type.
protected firstOfType ( )

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

This should be called after the filter has been parsed.
public getMatches ( ) : array
Результат array The matched items. This is almost always an array of {@link DOMElement} objects. It is always an instance of {@link DOMNode} objects.

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

This can also be used as a general filtering routine.
public has ( $filter )

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

Pseudo-class handler for :lang.
protected lang ( $value )

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

Pseudo-class handler for :last-of-type.
protected lastOfType ( )

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

public matches ( )

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

This does not follow the specification in the following way: The CSS 3 selector spec says the value of not() must be a simple selector. This function allows complex selectors.
protected not ( string $filter )
$filter string A CSS selector.

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

Pseudo-class handler for nth-child and all related pseudo-classes.
protected nthChild ( integer $groupSize, integer $elementInGroup, boolean $lastChild = false )
$groupSize integer The size of the group (in an+b, this is a).
$elementInGroup integer The offset in a group. (in an+b this is b).
$lastChild boolean Whether counting should begin with the last child. By default, this is false. Pseudo-classes that start with the last-child can set this to true.

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

Pseudo-class handler for :nth-last-child and related pseudo-classes.
protected nthLastChild ( $groupSize, $elementInGroup )

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

Not implemented.
protected nthLastOfTypeChild ( $groupSize, $elementInGroup )

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

Not implemented.
protected nthOfTypeChild ( $groupSize, $elementInGroup, $lastChild )

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

Pseudo-class handler for :only-child.
protected onlyChild ( )

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

Pseudo-class handler for :only-of-type.
protected onlyOfType ( )

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

Parse an an+b rule for CSS pseudo-classes.
protected parseAnB ( $rule )
$rule Some rule in the an+b format.

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

This also supports the following nonstandard pseudo classes: - :x-reset/:x-root (reset to the main item passed into the constructor. Less drastic than :root) - :odd/:even (shorthand for :nth-child(odd)/:nth-child(even)).
public pseudoClass ( $name, $value = null )

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

As the spec mentions, these must be at the end of a selector or else they will cause errors. Most selectors return elements. Pseudo-elements do not.
public pseudoElement ( $name )

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

Helper function to find all elements with exact matches.
Устаревший: All use cases seem to be covered by attribute().
protected searchForAttr ( $name, $value = null )

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

If two passed in items are siblings of each other, neither will be included in the list of siblings. Their status as being candidates excludes them from being considered siblings.
public sibling ( )

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

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

The matches
protected $alreadyMatched

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

protected $dom

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

Matches found before current selector.
protected $findAnyElement

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

Always points to the top level.
protected $matches