PHP Class FluentDOM\Nodes

Inheritance: implements ArrayAccess, implements Countable, implements IteratorAggregate
Afficher le fichier Open project: fluentdom/fluentdom Class Usage Examples

Protected Properties

Свойство Type Description
$_nodes DOMNode[]
$_parent Nodes | null
$_useDocumentContext boolean Use document context for expression (not selected nodes).

Méthodes publiques

Méthode Description
__construct ( mixed $source = NULL, null | string $contentType = 'text/xml' )
__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
__toString ( ) : string Return the output of the internal dom document
__unset ( string $name ) Throws an exception if somebody tries to unset one of the dynamic properties
count ( ) : integer Countable interface
each ( callable $function, callable | boolean | null $elementsFilter = NULL ) Execute a function within the context of every matched element.
end ( ) : Nodes Return the parent FluentDOM\Nodes object.
find ( mixed $selector, integer $options ) : Nodes Searches for descendant elements that match the specified expression.
formatOutput ( string $contentType = NULL ) : Nodes Formats the current document, resets internal node array and other properties.
getDocument ( ) : DOMDocument | Document Get the associated DOM, create one if here isn't one yet.
getIterator ( ) : NodesIterator IteratorAggregate interface
getLoadingOptions ( null | string $contentType = NULL ) : array | mixed Return the options from the original loading action, but only if the content type equals the loaded content type.
getSelectorCallback ( null | callable | string | array | DOMNode | Traversable $selector ) : callable | null Returns a callback that can be used to validate if an node matches the selector.
index ( null | string | DOMNode | Traversable $selector = NULL ) : integer Search for a given element from among the matched elements.
item ( integer $position ) : DOMElement | DOMNode The item() method is used to access elements in the node list, like in a DOMNodeList.
load ( mixed $source, string $contentType = 'text/xml', array | Traversable | Options $options = [] ) Load a $source. The type of the source depends on the loaders. If no explicit loaders are set it will use a set of default loaders for xml/html and json.
loaders ( fluentdom\Loadable | array | Traversable $loaders = NULL ) : fluentdom\Loadable Set the loaders list.
offsetExists ( integer $offset ) : boolean Check if index exists in internal array
offsetGet ( integer $offset ) : DOMElement | DOMNode | null Get element from internal array
offsetSet ( integer $offset, mixed $value ) If somebody tries to modify the internal array throw an exception.
offsetUnset ( integer $offset ) If somebody tries to remove an element from the internal array throw an exception.
prepareSelector ( string $selector, integer $contextMode ) : string Use callback to convert selector if it is set.
push ( DOMNode | Traversable | array | null $elements, boolean $ignoreTextNodes = FALSE ) Push new element(s) an the internal element list
registerNamespace ( string $prefix, string $namespace ) Register a namespace for selectors/expressions
serializerFactories ( Group $factories = NULL ) : Group
spawn ( array | Traversable | DOMNode | Nodes $elements = NULL ) : Nodes Create a new instance of the same class with $this as the parent. This is used for the chaining.
toArray ( ) : DOMNode[] Retrieve the matched DOM nodes in an array.
toString ( ) : string Return the output of the internal dom document
unique ( array $array ) : array Sorts an array of DOM nodes based on document position, in place, with the duplicates removed.
xpath ( string $expression = NULL, DOMNode $contextNode = NULL ) : Xpath | DOMNodeList | float | string

Méthodes protégées

Méthode Description
fetch ( string $expression, null | string | callable | DOMNode | array | Traversable $filter = NULL, null | string | callable | DOMNode | array | Traversable $stopAt = NULL, integer $options ) : Nodes Fetch spawns and fills a Nodes instance.
matches ( string $selector, DOMNode $context = NULL ) : boolean Test that selector matches context and return true/false

Private Methods

Méthode Description
applyNamespaces ( ) apply stored namespaces to attached document or xpath object
getXpath ( ) : Xpath
prepareFindContext ( mixed $selector, integer $options ) : array
prepareSelectorAsFilter ( $selector, $contextMode )
prepareSource ( mixed $source, string $contentType, array | Traversable | Options $options ) : boolean | DOMDocument | Document | null
setContentType ( string $value ) Setter for Nodes::_contentType property

Method Details

__construct() public méthode

public __construct ( mixed $source = NULL, null | string $contentType = 'text/xml' )
$source mixed
$contentType null | string

__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

__toString() public méthode

Return the output of the internal dom document
public __toString ( ) : string
Résultat string

__unset() public méthode

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

count() public méthode

Countable interface
public count ( ) : integer
Résultat integer

each() public méthode

If $elementsOnly is a callable the return value defines if it is called for that node. If $elementsOnly is set to TRUE, only element nodes are used.
public each ( callable $function, callable | boolean | null $elementsFilter = NULL )
$function callable
$elementsFilter callable | boolean | null

end() public méthode

Return the parent FluentDOM\Nodes object.
public end ( ) : Nodes
Résultat Nodes

fetch() protected méthode

Fetch spawns and fills a Nodes instance.
protected fetch ( string $expression, null | string | callable | DOMNode | array | Traversable $filter = NULL, null | string | callable | DOMNode | array | Traversable $stopAt = NULL, integer $options ) : Nodes
$expression string Xpath expression
$filter null | string | callable | DOMNode | array | Traversable
$stopAt null | string | callable | DOMNode | array | Traversable
$options integer
Résultat Nodes

find() public méthode

If the $selector is an node or a list of nodes all descendants that match that node/node list are returned. self::CONTEXT_DOCUMENT will use the document element as context. Otherwise the currently nodes are used as contexts self::FIND_MODE_FILTER will use the $selector only as filter and not execute it directly. this is the like the jQuery specification - but a lot slower and needs more memory. Additionally in this mode, it will find only element nodes. *
public find ( mixed $selector, integer $options ) : Nodes
$selector mixed selector
$options integer FIND_* options CONTEXT_DOCUMENT, FIND_MODE_FILTER, FIND_FORCE_SORT
Résultat Nodes

formatOutput() public méthode

The document is saved and reloaded, all variables with DOMNodes of this document will get invalid.
public formatOutput ( string $contentType = NULL ) : Nodes
$contentType string
Résultat Nodes

getDocument() public méthode

Get the associated DOM, create one if here isn't one yet.
public getDocument ( ) : DOMDocument | Document
Résultat DOMDocument | Document

getIterator() public méthode

IteratorAggregate interface
public getIterator ( ) : NodesIterator
Résultat FluentDOM\Iterators\NodesIterator

getLoadingOptions() public méthode

Return the options from the original loading action, but only if the content type equals the loaded content type.
public getLoadingOptions ( null | string $contentType = NULL ) : array | mixed
$contentType null | string
Résultat array | mixed

getSelectorCallback() public méthode

Returns a callback that can be used to validate if an node matches the selector.
public getSelectorCallback ( null | callable | string | array | DOMNode | Traversable $selector ) : callable | null
$selector null | callable | string | array | DOMNode | Traversable
Résultat callable | null

index() public méthode

Search for a given element from among the matched elements.
public index ( null | string | DOMNode | Traversable $selector = NULL ) : integer
$selector null | string | DOMNode | Traversable
Résultat integer

item() public méthode

The item() method is used to access elements in the node list, like in a DOMNodeList.
public item ( integer $position ) : DOMElement | DOMNode
$position integer
Résultat DOMElement | DOMNode

load() public méthode

Load a $source. The type of the source depends on the loaders. If no explicit loaders are set it will use a set of default loaders for xml/html and json.
public load ( mixed $source, string $contentType = 'text/xml', array | Traversable | Options $options = [] )
$source mixed
$contentType string optional, default value 'text/xml'
$options array | Traversable | FluentDOM\Loader\Options

loaders() public méthode

Set the loaders list.
public loaders ( fluentdom\Loadable | array | Traversable $loaders = NULL ) : fluentdom\Loadable
$loaders fluentdom\Loadable | array | Traversable
Résultat fluentdom\Loadable

matches() protected méthode

Test that selector matches context and return true/false
protected matches ( string $selector, DOMNode $context = NULL ) : boolean
$selector string
$context DOMNode optional, default value NULL
Résultat boolean

offsetExists() public méthode

Check if index exists in internal array
public offsetExists ( integer $offset ) : boolean
$offset integer
Résultat boolean

offsetGet() public méthode

Get element from internal array
public offsetGet ( integer $offset ) : DOMElement | DOMNode | null
$offset integer
Résultat DOMElement | DOMNode | null

offsetSet() public méthode

If somebody tries to modify the internal array throw an exception.
public offsetSet ( integer $offset, mixed $value )
$offset integer
$value mixed

offsetUnset() public méthode

If somebody tries to remove an element from the internal array throw an exception.
public offsetUnset ( integer $offset )
$offset integer

prepareSelector() public méthode

Use callback to convert selector if it is set.
public prepareSelector ( string $selector, integer $contextMode ) : string
$selector string
$contextMode integer
Résultat string

push() public méthode

Push new element(s) an the internal element list
public push ( DOMNode | Traversable | array | null $elements, boolean $ignoreTextNodes = FALSE )
$elements DOMNode | Traversable | array | null
$ignoreTextNodes boolean ignore text nodes

registerNamespace() public méthode

Register a namespace for selectors/expressions
public registerNamespace ( string $prefix, string $namespace )
$prefix string
$namespace string

serializerFactories() public méthode

public serializerFactories ( Group $factories = NULL ) : Group
$factories FluentDOM\Serializer\Factory\Group
Résultat FluentDOM\Serializer\Factory\Group

spawn() public méthode

Create a new instance of the same class with $this as the parent. This is used for the chaining.
public spawn ( array | Traversable | DOMNode | Nodes $elements = NULL ) : Nodes
$elements array | Traversable | DOMNode | Nodes
Résultat Nodes

toArray() public méthode

Retrieve the matched DOM nodes in an array.
public toArray ( ) : DOMNode[]
Résultat DOMNode[]

toString() public méthode

Return the output of the internal dom document
public toString ( ) : string
Résultat string

unique() public méthode

Note that this only works on arrays of DOM nodes, not strings or numbers.
public unique ( array $array ) : array
$array array array of DOM nodes
Résultat array

xpath() public méthode

public xpath ( string $expression = NULL, DOMNode $contextNode = NULL ) : Xpath | DOMNodeList | float | string
$expression string
$contextNode DOMNode
Résultat Xpath | DOMNodeList | float | string

Property Details

$_nodes protected_oe property

protected DOMNode[] $_nodes
Résultat DOMNode[]

$_parent protected_oe property

protected Nodes,fluentdom|NULL $_parent
Résultat Nodes | null

$_useDocumentContext protected_oe property

Use document context for expression (not selected nodes).
protected bool $_useDocumentContext
Résultat boolean