Public Member Functions | Data Fields
Node Class Reference

General node for tree like structures. More...

Public Member Functions

 Node ($content, Node $parent=null, $children=array())
 
 addChild (Node $child)
 
 addChildAt (Node $child, $index)
 
 hasChild (Node $child)
 
 findChild (Node $child)
 
 findChildWith ($content)
 
 getChildAt ($index)
 
 getChildIndex (Node $child)
 
 getChildWith ($content)
 
 removeChild (Node $child)
 
 removeChildAt ($index)
 
 isLeaf ()
 
 isTop ()
 
 setContent ($content)
 
 setContentAfter ($content)
 
 __toString ()
 
 recursive ()
 

Data Fields

 $content = ''
 
 $content_after = ''
 
 $children = array()
 
 $parent = null
 

Detailed Description

General node for tree like structures.

Version
1.2
Author
DinuSV

Member Function Documentation

Node (   $content,
Node  $parent = null,
  $children = array() 
)

Constructor

Parameters
mixed$content
Node$parent: the parent of this node ( can be null )
array$children: children of this node
addChild ( Node  $child)

Add a child to this node

Parameters
Node$child
Returns
Node : current object
addChildAt ( Node  $child,
  $index 
)

Add a child at a specified position in this node

Parameters
Node$child
integer$index: the position to add the node at
Returns
Node : current object
hasChild ( Node  $child)

Check if this node has a given child

Parameters
Node$child
Returns
boolean : true if the child is found, false otherwise
findChild ( Node  $child)

Find a child in this Node by searching recursively in all it's children

Parameters
Node$child
Returns
boolean : true if the child is found, false otherwise
findChildWith (   $content)

Find a child in this Node, or in it's children that has the specified content

Parameters
string$content
Returns
boolean : true if the child is found, false otherwise
getChildAt (   $index)

Retrieve the node child at a given index

Parameters
integer$index
Returns
Node
getChildIndex ( Node  $child)

Get the index of a child

Parameters
Node$child
Returns
Node : the child if it's found
boolean : false if no child is found
getChildWith (   $content)

Get the child Node that contains the specified content.

Parameters
string$content
Returns
Node : the child if it's found
boolean : false if no child is found
removeChild ( Node  $child)

Remove a given child

Parameters
Node$child
Returns
Node : current object
removeChildAt (   $index)

Remove a child at a given position

Parameters
integer$index: the position of the child to be removed
Returns
Node : current object
isLeaf ( )

Check if this node is a leaf ( has any children )

Returns
boolean : true if it's a leaf, false otherwise
isTop ( )

Check if this node is on top of the hierarchy

Returns
boolean : true if it's on top, false otherwise
setContent (   $content)

Set the content of this node

Parameters
string$content
Returns
Node : current object
setContentAfter (   $content)

Set the content to be printed in case of recursion

Parameters
string$content
Returns
Node : current object
__toString ( )

To string method

Returns
string
recursive ( )

Recursive output of this node and it's children

Returns
string : the content and it's children

Field Documentation

$content = ''

mixed : Node content, will output before the nodes children in case of recursion

$content_after = ''

mixed : Content to output after the nodes children in case of recursion

$children = array()

array : Array of Node type elements

$parent = null

Node : The parent of the current node, this field is optional