PHP Класс Tale\Jade\Parser\Node

A node has children and always tries to reference its parents It also has some utility methods to work with those nodes
Автор: Torben Koehn ([email protected])
Автор: Talesoft ([email protected])
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$children Node[] The children of this node.
$line integer | null The line this node was created on.
$offset integer | null The offset in a line this node was created on.
$parent Node | null The parent-node of this node.
$type string The type of the node, can be a string of any kind.

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

Метод Описание
__construct ( string $type, integer | null $line = null, integer | null $offset = null ) Creates a new, detached node without children or a parent.
__debugInfo ( )
__get ( string $key ) : mixed Gets called when a property is read from this node.
__isset ( string $key ) : boolean Gets called when isset() is called on this node's properties.
__set ( string $key, mixed $value ) Gets called when a property is written on this node instance.
__toString ( ) : string Gets called when this node instance is casted to a string in any way
__unset ( string $key ) Gets called when unset() is called on this node's properties.
append ( Node $node ) Appends the given node to this node's children.
dump ( integer $level ) : string Dumps the node as a string to ease up debugging.
find ( string $type ) : Generator Finds nodes with the given type inside this nodes children.
findArray ( string $type ) : array Finds nodes with the given type inside this nodes children.
indexOf ( Node $node ) : integer | false Returns the position of the given node inside this node.
insertAfter ( Node $node, Node $newNode ) Inserts the second given node after the first given node inside this node's children.
insertBefore ( Node $node, Node $newNode ) Inserts the second given node before the first given node inside this node's children.
next ( ) : Node | null Returns the next sibling of this element or null, if if there isn't any.
prepend ( Node $node ) Prepends the given node to this node's children.
prev ( ) : Node | null Returns the previous sibling of this element or null, if if there isn't any.
remove ( Node $node ) Removes the given child node from this node's children.
text ( string $indentStyle = ' ', string $newLine = " ", integer $level ) : string Returns all text and child-texts in a single text.

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

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

It can be appended to any node after that The type can be any kind of string
public __construct ( string $type, integer | null $line = null, integer | null $offset = null )
$type string the type of this node
$line integer | null the line at which we found this node
$offset integer | null the offset in a line we found this node at

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

public __debugInfo ( )

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

Redirects to the $_data storage and returns a reference to that value
public __get ( string $key ) : mixed
$key string the name of the property that is read
Результат mixed a reference to the value of the property

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

Redirects the call to the $_data storage
public __isset ( string $key ) : boolean
$key string the name of the property to check
Результат boolean

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

Redirects to the $_data storage and sets a key with that value there
public __set ( string $key, mixed $value )
$key string the name of the property to be written
$value mixed the value of that property

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

(echo, (string), strval, string operations, ., etc.) Calls ->dump() and dumps a debuggable text-representation of this node and all of its child-nodes
public __toString ( ) : string
Результат string a debuggable text-representation of this node tree

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

Redirects the call to $_data storage
public __unset ( string $key )
$key string the name of the property to unset

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

This also sets the parent of the given child to this node [element:a] (0)[element:b] (1)[element:c] [element:a]->append([element:d]) [element:a] (0)[element:b] (1)[element:c] (2)[element:d]
public append ( Node $node )
$node Node the new child node to be appended

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

This is also the default-action for __toString on every node The result will look like this: [element tag=a expands=[element tag=b]] [element tag=c attributes={[attribute name=d name=e]}]
public dump ( integer $level ) : string
$level integer the initial indentation level
Результат string the string to debug the node-tree

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

Plus all it's children-children recursively and returns a generator providing them This is used to collect all blocks, imports and mixins and handle them in a special way If you need a normal array, use ->findArray() instead instead
public find ( string $type ) : Generator
$type string the node type to search for
Результат Generator a generator of the found children

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

Plus all it's children-children recursively and returns an array with all of them I you want to do further searching on it, you should rather use the Generator-version ->find() to improve memory-usage
public findArray ( string $type ) : array
$type string the node type to search for
Результат array an array containing all found children

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

[element:a] (0)[element:b] (1)[element:c] (2)[element:d] [element:a]->indexOf([element:d]) === 2
См. также: array_search
public indexOf ( Node $node ) : integer | false
$node Node the child-node to get the index of
Результат integer | false

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

This allows fine control over the node's children The new nodes parent will be set to this node [element:a] (0)[element:b] (1)[element:c] [element:a]->insertAfter([element:b], [element:d]) [element:a] (0)[element:b] (1)[element:d] (2)[element:c]
public insertAfter ( Node $node, Node $newNode )
$node Node the child node of this node's children the new node will be inserted after
$newNode Node the new node that will be inserted after the first node

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

This allows fine control over the node's children The new nodes parent will be set to this node [element:a] (0)[element:b] (1)[element:c] [element:a]->insertBefore([element:c], [element:d]) [element:a] (0)[element:b] (1)[element:d] (2)[element:c]
public insertBefore ( Node $node, Node $newNode )
$node Node the child node of this node's children the new node will be inserted before
$newNode Node the new node that will be inserted before the first node

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

[element:a] (0)[element:b] (1)[element:c] [element:b]->next() === [element:c]
public next ( ) : Node | null
Результат Node | null

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

This also sets the parent of the given child to this node [element:a] (0)[element:b] (1)[element:c] [element:a]->prepend([element:d]) [element:a] (0)[element:d] (1)[element:b] (2)[element:c]
public prepend ( Node $node )
$node Node the new child node to be prepended

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

[element:a] (0)[element:b] (1)[element:c] [element:c]->prev() === [element:b]
public prev ( ) : Node | null
Результат Node | null

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

The parent of the given child node will be set to null [element:a] (0)[element:b] (1)[element:c] (2)[element:d] [element:a]->remove([element:c]) [element:a] (0)[element:b] (1)[element:d]
public remove ( Node $node )
$node Node the node to remove from this node's children

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

You can control the text-style with the arguments
public text ( string $indentStyle = ' ', string $newLine = " ", integer $level ) : string
$indentStyle string the indentation to use (multiplies with level)
$newLine string the new-line style to use
$level integer the initial indentation level
Результат string the compiled text-block

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

$children публичное свойство

The children of this node.
public Node[],Tale\Jade\Parser $children
Результат Node[]

$line публичное свойство

The line this node was created on.
public int|null $line
Результат integer | null

$offset публичное свойство

The offset in a line this node was created on.
public int|null $offset
Результат integer | null

$parent публичное свойство

The parent-node of this node.
public Node,Tale\Jade\Parser|null $parent
Результат Node | null

$type публичное свойство

The type of the node, can be a string of any kind.
public string $type
Результат string