PHP Class FluentDOM\Nodes

Inheritance: implements ArrayAccess, implements Countable, implements IteratorAggregate
Mostra file Open project: fluentdom/fluentdom Class Usage Examples

Protected Properties

Property Type Description
$_nodes DOMNode[]
$_parent Nodes | null
$_useDocumentContext boolean Use document context for expression (not selected nodes).

Public Methods

Method 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

Protected Methods

Method 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

Method 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 method

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

__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

__toString() public method

Return the output of the internal dom document
public __toString ( ) : string
return string

__unset() public method

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

count() public method

Countable interface
public count ( ) : integer
return integer

each() public method

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 method

Return the parent FluentDOM\Nodes object.
public end ( ) : Nodes
return Nodes

fetch() protected method

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
return Nodes

find() public method

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
return Nodes

formatOutput() public method

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

getDocument() public method

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

getIterator() public method

IteratorAggregate interface
public getIterator ( ) : NodesIterator
return FluentDOM\Iterators\NodesIterator

getLoadingOptions() public method

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
return array | mixed

getSelectorCallback() public method

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
return callable | null

index() public method

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

item() public method

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

load() public method

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 method

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

matches() protected method

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
return boolean

offsetExists() public method

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

offsetGet() public method

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

offsetSet() public method

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

offsetUnset() public method

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

prepareSelector() public method

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

push() public method

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 method

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

serializerFactories() public method

public serializerFactories ( Group $factories = NULL ) : Group
$factories FluentDOM\Serializer\Factory\Group
return FluentDOM\Serializer\Factory\Group

spawn() public method

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
return Nodes

toArray() public method

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

toString() public method

Return the output of the internal dom document
public toString ( ) : string
return string

unique() public method

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
return array

xpath() public method

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

Property Details

$_nodes protected_oe property

protected DOMNode[] $_nodes
return DOMNode[]

$_parent protected_oe property

protected Nodes,fluentdom|NULL $_parent
return Nodes | null

$_useDocumentContext protected_oe property

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