PHP Class 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
Datei anzeigen Open project: talesoft/tale-jade Class Usage Examples

Public Properties

Property Type Description
$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.

Public Methods

Method Description
__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.

Method Details

__construct() public method

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 method

public __debugInfo ( )

__get() public method

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
return mixed a reference to the value of the property

__isset() public method

Redirects the call to the $_data storage
public __isset ( string $key ) : boolean
$key string the name of the property to check
return boolean

__set() public method

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() public method

(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
return string a debuggable text-representation of this node tree

__unset() public method

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

append() public method

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() public method

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
return string the string to debug the node-tree

find() public method

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
return Generator a generator of the found children

findArray() public method

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
return array an array containing all found children

indexOf() public method

[element:a] (0)[element:b] (1)[element:c] (2)[element:d] [element:a]->indexOf([element:d]) === 2
See also: array_search
public indexOf ( Node $node ) : integer | false
$node Node the child-node to get the index of
return integer | false

insertAfter() public method

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() public method

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() public method

[element:a] (0)[element:b] (1)[element:c] [element:b]->next() === [element:c]
public next ( ) : Node | null
return Node | null

prepend() public method

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() public method

[element:a] (0)[element:b] (1)[element:c] [element:c]->prev() === [element:b]
public prev ( ) : Node | null
return Node | null

remove() public method

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() public method

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
return string the compiled text-block

Property Details

$children public_oe property

The children of this node.
public Node[],Tale\Jade\Parser $children
return Node[]

$line public_oe property

The line this node was created on.
public int|null $line
return integer | null

$offset public_oe property

The offset in a line this node was created on.
public int|null $offset
return integer | null

$parent public_oe property

The parent-node of this node.
public Node,Tale\Jade\Parser|null $parent
return Node | null

$type public_oe property

The type of the node, can be a string of any kind.
public string $type
return string