PHP Class FluentDOM\Query

Inheritance: extends Nodes
Show file Open project: fluentdom/fluentdom Class Usage Examples

Public Methods

Method Description
__call ( string $name, array $arguments ) : Query declaring an empty() or clone() method will crash the parser so we use some magic
__get ( string $name ) : mixed Virtual properties, read property
__isset ( string $name ) : boolean Virtual properties, validate existence
__set ( string $name, mixed $value ) Block changing the readonly dynamic property
__unset ( string $name ) Throws an exception if somebody tries to unset one of the dynamic properties
add ( string $selector, array | Traversable $context = NULL ) : Query Adds more elements, matched by the given expression, to the set of matched elements.
addBack ( ) : Query Add the previous selection to the current selection.
addClass ( string | callable $class ) : Query Adds the specified class(es) to each of the set of matched elements.
after ( string | array | DOMNode | DOMNodeList | Traversable | callable $content ) : Query Insert content after each of the matched elements.
andSelf ( ) : Query Alias for addBack()
append ( string | array | DOMNode | Traversable | callable $content ) : Query Append content to the inside of every matched element.
appendTo ( string | array | DOMNode | DOMNodeList | Query $selector ) : Query Append all of the matched elements to another, specified, set of elements.
attr ( string | array $attribute, variadic<[callable | string]> $arguments ) : Query | string Access a property on the first matched element or set the attribute(s) of all matched elements
before ( string | array | DOMNode | Traversable | callable $content ) : Query Insert content before each of the matched elements.
children ( string $selector = NULL ) : Query Get a set of elements containing of the unique immediate child nodes including only elements (not text nodes) of each of the matched set of elements.
closest ( string $selector, array | Traversable $context = NULL ) : Query Get a set of elements containing the closest parent element that matches the specified selector, the starting element included.
contents ( ) : Query Get a set of elements containing all of the unique immediate child nodes including elements and text nodes of each of the matched set of elements.
css ( string | array $property, variadic<[string | object | callable]> $arguments ) : string | null | $this get or set CSS values in style attributes
data ( string | array $name, $arguments ) : mixed Read a data attribute from the first node or set data attributes on all selected nodes.
eq ( integer $position ) : Query Reduce the set of matched elements to a single element.
filter ( string | callable $selector ) : Query Removes all elements from the set of matched elements that do not match the specified expression(s).
first ( ) : Query Get a set of elements containing only the first of the currently selected elements.
get ( $position = NULL ) : array Retrieve the matched DOM elements in an array. A negative position will be counted from the end.
has ( string | DOMNode $selector ) : Query Reduce the set of matched elements to those that have a descendant that matches the selector or DOM element.
hasAttr ( string $name ) : boolean Returns true if the specified attribute is present on at least one of the set of matched elements.
hasClass ( string $class ) : boolean Returns true if the specified class is present on at least one of the set of matched elements.
hasData ( DOMElement $element = NULL ) : boolean Validate if the element has an data attributes attached. If it is called without an actual $element parameter, it will check the first matched node.
html ( string | callable | null $html = NULL ) : string | self Get html contents of the first matched element or set the html contents of all selected element nodes.
insertAfter ( string | array | DOMNode | Traversable $selector ) : Query Insert all of the matched elements after another, specified, set of elements.
insertBefore ( string | array | DOMNode | Traversable $selector ) : Query Insert all of the matched elements before another, specified, set of elements.
is ( string $selector ) : boolean Checks the current selection against an expression and returns true, if at least one element of the selection fits the given expression.
last ( ) : Query Get a set of elements containing only the last of the currently selected elements.
map ( callable $function ) : array Translate a set of elements in the FluentDOM\Query object into another set of values in an array (which may, or may not contain elements).
next ( string $selector = NULL ) : Query Get a set of elements containing the unique next siblings of each of the given set of elements.
nextAll ( string $selector = NULL ) : Query Find all sibling elements after the current element.
nextUntil ( string $selector = NULL, string $filter = NULL ) : Query Get all following siblings of each element up to but not including the element matched by the selector.
not ( string | callback $selector ) : Query Removes elements matching the specified expression from the set of matched elements.
outerHtml ( string | callable | null $html = NULL ) : string | self Get the first matched node as HTML or replace each matched nodes with the provided fragment.
outerXml ( string | callable | null $xml = NULL ) : string | self Get the first matched node as XML or replace each matched nodes with the provided fragment.
parent ( ) : Query Get a set of elements containing the unique parents of the matched set of elements.
parents ( string $selector = NULL ) : Query Get the ancestors of each element in the current set of matched elements, optionally filtered by a selector.
parentsUntil ( string $stopAt = NULL, string $filter = NULL ) : Query Get the ancestors of each element in the current set of matched elements, up to but not including the element matched by the selector.
prepend ( string | array | DOMNode | Traversable $content ) : Query Prepend content to the inside of every matched element.
prependTo ( string | array | DOMNode | DOMNodeList | Query $selector ) : Query Prepend all of the matched elements to another, specified, set of elements.
prev ( string $selector = NULL ) : Query Get a set of elements containing the unique previous siblings of each of the matched set of elements.
prevAll ( string $selector = NULL ) : Query Find all sibling elements in front of the current element.
prevUntil ( string $selector = NULL, string $filter = NULL ) : Query Get all preceding siblings of each element up to but not including the element matched by the selector.
remove ( string $selector = NULL ) : Query Removes all matched elements from the DOM.
removeAttr ( string | array $name ) : Query Remove an attribute from each of the matched elements. If $name is NULL or *, all attributes will be deleted.
removeClass ( string | callable $class = '' ) : Query Removes all or the specified class(es) from the set of matched elements.
removeData ( string | array | null $name = NULL ) : Query Remove an data - attribute from each of the matched elements. If $name is NULL or *, all data attributes will be deleted.
replaceAll ( string | array | DOMNode | Traversable $selector ) : Query Replaces the elements matched by the specified selector with the matched elements.
replaceWith ( string | array | DOMNode | Traversable | callable $content ) : Query Replaces all matched elements with the specified HTML or DOM elements.
reverse ( ) : Query Reverse the order of the matched elements.
siblings ( string $selector = NULL ) : Query Get a set of elements containing all of the unique siblings of each of the matched set of elements.
slice ( integer $start, integer $end = NULL ) : Query Selects a subset of the matched elements.
text ( string | callable $text = NULL ) : string | Query Get the combined text contents of all matched elements or set the text contents of all matched elements.
toggleClass ( string | callable $class, null | boolean $switch = NULL ) : Query Adds the specified classes if the switch is TRUE, removes the specified classes if the switch is FALSE, toggles the specified classes if the switch is NULL.
wrap ( string | array | DOMNode | Traversable | callable $content ) : Query Wrap each matched element with the specified content.
wrapAll ( string | array | DOMNode | Traversable $content ) : Query Wrap al matched elements with the specified content
wrapInner ( string | array | DOMNode | Traversable $content ) : Query Wrap the inner child contents of each matched element (including text nodes) with an XML structure.
xml ( string | callable | null $xml = NULL ) : string | self Get xml contents of the first matched element or set the xml contents of all selected element nodes.

Private Methods

Method Description
apply ( array | DOMNodeList $targetNodes, string | array | DOMNode | DOMNodeList | Traversable | callable $content, callable $handler ) : array Use a handler callback to apply a content argument to each node $targetNodes. The content argument can be an easy setter function
applyToSelector ( string | array | DOMNode | Traversable $selector, callable $handler, boolean $remove = FALSE ) : Query Apply the handler the $handler to nodes defined by selector, using the currently selected nodes as context.
applyToSpawn ( array | DOMNodeList $targetNodes, string | array | DOMNode | DOMNodeList | Traversable | callable $content, callable $handler, boolean $remove = FALSE ) : Query Apply the content to the target nodes using the handler callback and push them into a spawned Query object.
build ( ) : Builder
changeClassString ( string $current, string $toggle, boolean | null $switch ) : FALSE | string Change a class string
cloneNodes ( ) : Query Clone matched DOM Elements and select the clones.
content ( string | callable | null $content, callable $export, callable $import, callable $insert )
emptyNodes ( ) : Query Remove all child nodes from the set of matched elements.
getFirstElement ( ) : null | DOMElement Returns the item from the internal array if if the index exists and is an DOMElement
getGroupedNodes ( ) : array | boolean group selected elements by previous node - ignore whitespace text nodes
getNamesList ( string | array | null $names ) : array
getSetterValues ( string | array | Traversable $name, string | float | integer | null | callable $value ) : array | Traversable
modify ( DOMNode $node ) : Modifier
outerContent ( string | callable | null $content, callable $export, callable $import )
wrapGroupedNodes ( array $groups, DOMElement $template ) : array Wrap grouped nodes
wrapNodes ( array $elements, string | array | DOMNode | Traversable | callable $content ) : Query Wrap $content around a set of elements

Method Details

__call() public method

declaring an empty() or clone() method will crash the parser so we use some magic
public __call ( string $name, array $arguments ) : Query
$name string
$arguments array
return Query

__get() public method

Virtual properties, read property
public __get ( string $name ) : mixed
$name string
return mixed

__isset() public method

Virtual properties, validate existence
public __isset ( string $name ) : boolean
$name string
return boolean

__set() public method

Block changing the readonly dynamic property
public __set ( string $name, mixed $value )
$name string
$value mixed

__unset() public method

Throws an exception if somebody tries to unset one of the dynamic properties
public __unset ( string $name )
$name string

add() public method

Adds more elements, matched by the given expression, to the set of matched elements.
public add ( string $selector, array | Traversable $context = NULL ) : Query
$selector string selector
$context array | Traversable
return Query

addBack() public method

Add the previous selection to the current selection.
public addBack ( ) : Query
return Query

addClass() public method

Adds the specified class(es) to each of the set of matched elements.
public addClass ( string | callable $class ) : Query
$class string | callable
return Query

after() public method

Insert content after each of the matched elements.
public after ( string | array | DOMNode | DOMNodeList | Traversable | callable $content ) : Query
$content string | array | DOMNode | DOMNodeList | Traversable | callable
return Query

andSelf() public method

Alias for addBack()
Deprecation:
public andSelf ( ) : Query
return Query

append() public method

Append content to the inside of every matched element.
public append ( string | array | DOMNode | Traversable | callable $content ) : Query
$content string | array | DOMNode | Traversable | callable DOMNode or DOMNodeList or xml fragment string
return Query

appendTo() public method

Returns all of the inserted elements.
public appendTo ( string | array | DOMNode | DOMNodeList | Query $selector ) : Query
$selector string | array | DOMNode | DOMNodeList | Query
return Query

attr() public method

Access a property on the first matched element or set the attribute(s) of all matched elements
public attr ( string | array $attribute, variadic<[callable | string]> $arguments ) : Query | string
$attribute string | array attribute name or attribute list
$arguments variadic<[callable | string]>
return Query | string attribute value or $this

before() public method

Insert content before each of the matched elements.
public before ( string | array | DOMNode | Traversable | callable $content ) : Query
$content string | array | DOMNode | Traversable | callable
return Query

children() public method

Get a set of elements containing of the unique immediate child nodes including only elements (not text nodes) of each of the matched set of elements.
public children ( string $selector = NULL ) : Query
$selector string selector
return Query

closest() public method

Get a set of elements containing the closest parent element that matches the specified selector, the starting element included.
public closest ( string $selector, array | Traversable $context = NULL ) : Query
$selector string selector
$context array | Traversable
return Query

contents() public method

Get a set of elements containing all of the unique immediate child nodes including elements and text nodes of each of the matched set of elements.
public contents ( ) : Query
return Query

css() public method

get or set CSS values in style attributes
public css ( string | array $property, variadic<[string | object | callable]> $arguments ) : string | null | $this
$property string | array
$arguments variadic<[string | object | callable]>
return string | null | $this

data() public method

Read a data attribute from the first node or set data attributes on all selected nodes.
public data ( string | array $name, $arguments ) : mixed
$name string | array data attribute identifier or array of data attributes to set
return mixed

eq() public method

Reduce the set of matched elements to a single element.
public eq ( integer $position ) : Query
$position integer Element index (start with 0)
return Query

filter() public method

Removes all elements from the set of matched elements that do not match the specified expression(s).
public filter ( string | callable $selector ) : Query
$selector string | callable selector or callback function
return Query

first() public method

Get a set of elements containing only the first of the currently selected elements.
public first ( ) : Query
return Query

get() public method

Retrieve the matched DOM elements in an array. A negative position will be counted from the end.
public get ( $position = NULL ) : array
return array

has() public method

Reduce the set of matched elements to those that have a descendant that matches the selector or DOM element.
public has ( string | DOMNode $selector ) : Query
$selector string | DOMNode selector or DOMNode
return Query

hasAttr() public method

Returns true if the specified attribute is present on at least one of the set of matched elements.
public hasAttr ( string $name ) : boolean
$name string
return boolean

hasClass() public method

Returns true if the specified class is present on at least one of the set of matched elements.
public hasClass ( string $class ) : boolean
$class string
return boolean

hasData() public method

Validate if the element has an data attributes attached. If it is called without an actual $element parameter, it will check the first matched node.
public hasData ( DOMElement $element = NULL ) : boolean
$element DOMElement
return boolean

html() public method

Get html contents of the first matched element or set the html contents of all selected element nodes.
public html ( string | callable | null $html = NULL ) : string | self
$html string | callable | null
return string | self

insertAfter() public method

Insert all of the matched elements after another, specified, set of elements.
public insertAfter ( string | array | DOMNode | Traversable $selector ) : Query
$selector string | array | DOMNode | Traversable
return Query

insertBefore() public method

Insert all of the matched elements before another, specified, set of elements.
public insertBefore ( string | array | DOMNode | Traversable $selector ) : Query
$selector string | array | DOMNode | Traversable
return Query

is() public method

Checks the current selection against an expression and returns true, if at least one element of the selection fits the given expression.
public is ( string $selector ) : boolean
$selector string selector
return boolean

last() public method

Get a set of elements containing only the last of the currently selected elements.
public last ( ) : Query
return Query

map() public method

If the callback function returns an array each element of the array will be added to the result array. All other variable types are put directly into the result array.
public map ( callable $function ) : array
$function callable
return array

next() public method

Get a set of elements containing the unique next siblings of each of the given set of elements.
public next ( string $selector = NULL ) : Query
$selector string
return Query

nextAll() public method

Find all sibling elements after the current element.
public nextAll ( string $selector = NULL ) : Query
$selector string selector
return Query

nextUntil() public method

Get all following siblings of each element up to but not including the element matched by the selector.
public nextUntil ( string $selector = NULL, string $filter = NULL ) : Query
$selector string selector
$filter string selector
return Query

not() public method

Removes elements matching the specified expression from the set of matched elements.
public not ( string | callback $selector ) : Query
$selector string | callback selector or callback function
return Query

outerHtml() public method

Get the first matched node as HTML or replace each matched nodes with the provided fragment.
public outerHtml ( string | callable | null $html = NULL ) : string | self
$html string | callable | null
return string | self

outerXml() public method

Get the first matched node as XML or replace each matched nodes with the provided fragment.
public outerXml ( string | callable | null $xml = NULL ) : string | self
$xml string | callable | null
return string | self

parent() public method

Get a set of elements containing the unique parents of the matched set of elements.
public parent ( ) : Query
return Query

parents() public method

Get the ancestors of each element in the current set of matched elements, optionally filtered by a selector.
public parents ( string $selector = NULL ) : Query
$selector string selector
return Query

parentsUntil() public method

Get the ancestors of each element in the current set of matched elements, up to but not including the element matched by the selector.
public parentsUntil ( string $stopAt = NULL, string $filter = NULL ) : Query
$stopAt string selector
$filter string selector
return Query

prepend() public method

Prepend content to the inside of every matched element.
public prepend ( string | array | DOMNode | Traversable $content ) : Query
$content string | array | DOMNode | Traversable
return Query

prependTo() public method

Returns all of the inserted elements.
public prependTo ( string | array | DOMNode | DOMNodeList | Query $selector ) : Query
$selector string | array | DOMNode | DOMNodeList | Query
return Query list of all new elements

prev() public method

Get a set of elements containing the unique previous siblings of each of the matched set of elements.
public prev ( string $selector = NULL ) : Query
$selector string selector
return Query

prevAll() public method

Find all sibling elements in front of the current element.
public prevAll ( string $selector = NULL ) : Query
$selector string selector
return Query

prevUntil() public method

Get all preceding siblings of each element up to but not including the element matched by the selector.
public prevUntil ( string $selector = NULL, string $filter = NULL ) : Query
$selector string selector
$filter string selector
return Query

remove() public method

Removes all matched elements from the DOM.
public remove ( string $selector = NULL ) : Query
$selector string selector
return Query removed elements

removeAttr() public method

Remove an attribute from each of the matched elements. If $name is NULL or *, all attributes will be deleted.
public removeAttr ( string | array $name ) : Query
$name string | array
return Query

removeClass() public method

Removes all or the specified class(es) from the set of matched elements.
public removeClass ( string | callable $class = '' ) : Query
$class string | callable
return Query

removeData() public method

Remove an data - attribute from each of the matched elements. If $name is NULL or *, all data attributes will be deleted.
public removeData ( string | array | null $name = NULL ) : Query
$name string | array | null
return Query

replaceAll() public method

Replaces the elements matched by the specified selector with the matched elements.
public replaceAll ( string | array | DOMNode | Traversable $selector ) : Query
$selector string | array | DOMNode | Traversable
return Query

replaceWith() public method

This returns the element that was just replaced, which has been removed from the DOM.
public replaceWith ( string | array | DOMNode | Traversable | callable $content ) : Query
$content string | array | DOMNode | Traversable | callable
return Query

reverse() public method

Reverse the order of the matched elements.
public reverse ( ) : Query
return Query

siblings() public method

Get a set of elements containing all of the unique siblings of each of the matched set of elements.
public siblings ( string $selector = NULL ) : Query
$selector string selector
return Query

slice() public method

Selects a subset of the matched elements.
public slice ( integer $start, integer $end = NULL ) : Query
$start integer
$end integer
return Query

text() public method

Get the combined text contents of all matched elements or set the text contents of all matched elements.
public text ( string | callable $text = NULL ) : string | Query
$text string | callable
return string | Query

toggleClass() public method

Adds the specified classes if the switch is TRUE, removes the specified classes if the switch is FALSE, toggles the specified classes if the switch is NULL.
public toggleClass ( string | callable $class, null | boolean $switch = NULL ) : Query
$class string | callable
$switch null | boolean toggle if NULL, add if TRUE, remove if FALSE
return Query

wrap() public method

If $content contains several elements the first one is used
public wrap ( string | array | DOMNode | Traversable | callable $content ) : Query
$content string | array | DOMNode | Traversable | callable
return Query

wrapAll() public method

If the matched elements are not siblings, wrap each group of siblings.
public wrapAll ( string | array | DOMNode | Traversable $content ) : Query
$content string | array | DOMNode | Traversable
return Query

wrapInner() public method

Wrap the inner child contents of each matched element (including text nodes) with an XML structure.
public wrapInner ( string | array | DOMNode | Traversable $content ) : Query
$content string | array | DOMNode | Traversable
return Query

xml() public method

Get xml contents of the first matched element or set the xml contents of all selected element nodes.
public xml ( string | callable | null $xml = NULL ) : string | self
$xml string | callable | null XML fragment
return string | self