PHP Class FluentDOM\Query

Inheritance: extends Nodes
Afficher le fichier Open project: fluentdom/fluentdom Class Usage Examples

Méthodes publiques

Méthode 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

Méthode 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 méthode

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
Résultat Query

__get() public méthode

Virtual properties, read property
public __get ( string $name ) : mixed
$name string
Résultat mixed

__isset() public méthode

Virtual properties, validate existence
public __isset ( string $name ) : boolean
$name string
Résultat boolean

__set() public méthode

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

__unset() public méthode

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

add() public méthode

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
Résultat Query

addBack() public méthode

Add the previous selection to the current selection.
public addBack ( ) : Query
Résultat Query

addClass() public méthode

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

after() public méthode

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
Résultat Query

andSelf() public méthode

Alias for addBack()
Deprecation:
public andSelf ( ) : Query
Résultat Query

append() public méthode

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
Résultat Query

appendTo() public méthode

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

attr() public méthode

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]>
Résultat Query | string attribute value or $this

before() public méthode

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

children() public méthode

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
Résultat Query

closest() public méthode

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
Résultat Query

contents() public méthode

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
Résultat Query

css() public méthode

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]>
Résultat string | null | $this

data() public méthode

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
Résultat mixed

eq() public méthode

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

filter() public méthode

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
Résultat Query

first() public méthode

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

get() public méthode

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

has() public méthode

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
Résultat Query

hasAttr() public méthode

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
Résultat boolean

hasClass() public méthode

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
Résultat boolean

hasData() public méthode

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
Résultat boolean

html() public méthode

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
Résultat string | self

insertAfter() public méthode

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
Résultat Query

insertBefore() public méthode

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
Résultat Query

is() public méthode

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
Résultat boolean

last() public méthode

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

map() public méthode

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
Résultat array

next() public méthode

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
Résultat Query

nextAll() public méthode

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

nextUntil() public méthode

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
Résultat Query

not() public méthode

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
Résultat Query

outerHtml() public méthode

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
Résultat string | self

outerXml() public méthode

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
Résultat string | self

parent() public méthode

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

parents() public méthode

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
Résultat Query

parentsUntil() public méthode

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
Résultat Query

prepend() public méthode

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

prependTo() public méthode

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

prev() public méthode

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
Résultat Query

prevAll() public méthode

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

prevUntil() public méthode

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
Résultat Query

remove() public méthode

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

removeAttr() public méthode

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
Résultat Query

removeClass() public méthode

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

removeData() public méthode

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
Résultat Query

replaceAll() public méthode

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
Résultat Query

replaceWith() public méthode

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
Résultat Query

reverse() public méthode

Reverse the order of the matched elements.
public reverse ( ) : Query
Résultat Query

siblings() public méthode

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
Résultat Query

slice() public méthode

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

text() public méthode

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
Résultat string | Query

toggleClass() public méthode

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
Résultat Query

wrap() public méthode

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
Résultat Query

wrapAll() public méthode

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
Résultat Query

wrapInner() public méthode

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
Résultat Query

xml() public méthode

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
Résultat string | self