PHP Class 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:
Inheritance: implements QueryPath\CSS\EventHandler, implements QueryPath\CSS\Traverser
ファイルを表示 Open project: microweber/microweber Class Usage Examples

Protected Properties

Property Type Description
$alreadyMatched The matches
$dom
$findAnyElement Matches found before current selector.
$matches Always points to the top level.

Public Methods

Method Description
__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.

Protected Methods

Method Description
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.

Private Methods

Method Description
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.

Method Details

__construct() public method

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

adjacent() public method

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 method

public anotherSelector ( )

anyDescendant() public method

Get any descendant.
public anyDescendant ( )

anyElement() public method

public anyElement ( )

anyElementInNS() public method

public anyElementInNS ( $ns )

attachNodeList() public method

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

attrValMatches() protected method

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

attribute() public method

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

attributeNS() public method

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

directDescendant() public method

public directDescendant ( )

element() public method

Inherited
public element ( $name )

elementClass() public method

public elementClass ( $name )

elementID() public method

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() public method

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

emptyElement() protected method

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

find() public method

This is the primary searching method used throughout QueryPath.
public find ( string $filter ) : QueryPathEventHandler
$filter string A valid CSS 3 filter.
return QueryPathEventHandler Returns itself.

firstOfType() protected method

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

getMatches() public method

This should be called after the filter has been parsed.
public getMatches ( ) : array
return array The matched items. This is almost always an array of {@link DOMElement} objects. It is always an instance of {@link DOMNode} objects.

has() public method

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

lang() protected method

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

lastOfType() protected method

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

matches() public method

public matches ( )

not() protected method

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() protected method

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() protected method

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

nthLastOfTypeChild() protected method

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

nthOfTypeChild() protected method

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

onlyChild() protected method

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

onlyOfType() protected method

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

parseAnB() protected method

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

pseudoClass() public method

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() public method

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() protected method

Helper function to find all elements with exact matches.
Deprecation: All use cases seem to be covered by attribute().
protected searchForAttr ( $name, $value = null )

sibling() public method

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

Property Details

$alreadyMatched protected_oe property

The matches
protected $alreadyMatched

$dom protected_oe property

protected $dom

$findAnyElement protected_oe property

Matches found before current selector.
protected $findAnyElement

$matches protected_oe property

Always points to the top level.
protected $matches