PHP Класс FluentDOM\Nodes

Наследование: implements ArrayAccess, implements Countable, implements IteratorAggregate
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$_nodes DOMNode[]
$_parent Nodes | null
$_useDocumentContext boolean Use document context for expression (not selected nodes).

Открытые методы

Метод Описание
__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

Защищенные методы

Метод Описание
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

Приватные методы

Метод Описание
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

Описание методов

__construct() публичный Метод

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

__get() публичный Метод

Virtual properties, read property
public __get ( string $name ) : mixed
$name string
Результат mixed

__isset() публичный Метод

Virtual properties, validate existence
public __isset ( string $name ) : boolean
$name string
Результат boolean

__set() публичный Метод

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

__toString() публичный Метод

Return the output of the internal dom document
public __toString ( ) : string
Результат string

__unset() публичный Метод

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

count() публичный Метод

Countable interface
public count ( ) : integer
Результат integer

each() публичный Метод

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() публичный Метод

Return the parent FluentDOM\Nodes object.
public end ( ) : Nodes
Результат Nodes

fetch() защищенный Метод

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
Результат Nodes

find() публичный Метод

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
Результат Nodes

formatOutput() публичный Метод

The document is saved and reloaded, all variables with DOMNodes of this document will get invalid.
public formatOutput ( string $contentType = NULL ) : Nodes
$contentType string
Результат Nodes

getDocument() публичный Метод

Get the associated DOM, create one if here isn't one yet.
public getDocument ( ) : DOMDocument | Document
Результат DOMDocument | Document

getIterator() публичный Метод

IteratorAggregate interface
public getIterator ( ) : NodesIterator
Результат FluentDOM\Iterators\NodesIterator

getLoadingOptions() публичный Метод

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
Результат array | mixed

getSelectorCallback() публичный Метод

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
Результат callable | null

index() публичный Метод

Search for a given element from among the matched elements.
public index ( null | string | DOMNode | Traversable $selector = NULL ) : integer
$selector null | string | DOMNode | Traversable
Результат integer

item() публичный Метод

The item() method is used to access elements in the node list, like in a DOMNodeList.
public item ( integer $position ) : DOMElement | DOMNode
$position integer
Результат DOMElement | DOMNode

load() публичный Метод

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() публичный Метод

Set the loaders list.
public loaders ( fluentdom\Loadable | array | Traversable $loaders = NULL ) : fluentdom\Loadable
$loaders fluentdom\Loadable | array | Traversable
Результат fluentdom\Loadable

matches() защищенный Метод

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
Результат boolean

offsetExists() публичный Метод

Check if index exists in internal array
public offsetExists ( integer $offset ) : boolean
$offset integer
Результат boolean

offsetGet() публичный Метод

Get element from internal array
public offsetGet ( integer $offset ) : DOMElement | DOMNode | null
$offset integer
Результат DOMElement | DOMNode | null

offsetSet() публичный Метод

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

offsetUnset() публичный Метод

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

prepareSelector() публичный Метод

Use callback to convert selector if it is set.
public prepareSelector ( string $selector, integer $contextMode ) : string
$selector string
$contextMode integer
Результат string

push() публичный Метод

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() публичный Метод

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

serializerFactories() публичный Метод

public serializerFactories ( Group $factories = NULL ) : Group
$factories FluentDOM\Serializer\Factory\Group
Результат FluentDOM\Serializer\Factory\Group

spawn() публичный Метод

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
Результат Nodes

toArray() публичный Метод

Retrieve the matched DOM nodes in an array.
public toArray ( ) : DOMNode[]
Результат DOMNode[]

toString() публичный Метод

Return the output of the internal dom document
public toString ( ) : string
Результат string

unique() публичный Метод

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
Результат array

xpath() публичный Метод

public xpath ( string $expression = NULL, DOMNode $contextNode = NULL ) : Xpath | DOMNodeList | float | string
$expression string
$contextNode DOMNode
Результат Xpath | DOMNodeList | float | string

Описание свойств

$_nodes защищенное свойство

protected DOMNode[] $_nodes
Результат DOMNode[]

$_parent защищенное свойство

protected Nodes,fluentdom|NULL $_parent
Результат Nodes | null

$_useDocumentContext защищенное свойство

Use document context for expression (not selected nodes).
protected bool $_useDocumentContext
Результат boolean