Since: 4.0.0

trait NodeTrait

Defines the trait for a Node Interface Trait Class.

Traits

Defines the trait for an Immutable Node Class.

Properties

protected NodeInterface Since: 1.6
$_parent

Parent node object

from  ImmutableNodeTrait
protected NodeInterface[] Since: 1.6
$_children

Array of Children

from  ImmutableNodeTrait
protected NodeInterface Since: 1.6
$_leftSibling

Node left of this one

from  ImmutableNodeTrait
protected NodeInterface Since: 1.6
$_rightSibling

Node right of this one

from  ImmutableNodeTrait

Methods

getChildren(bool $recursive = false)

Get the children of this node

getParent()

Get the parent of this node

getRoot()

Get the root of the tree

bool
hasChildren()

Test if this node has children

bool
hasParent()

Test if this node has a parent

getSibling(bool $right = true)

Returns the right or left sibling of a node

void
setParent(NodeInterface $parent)

Set the parent of this node

void
addChild(NodeInterface $child)

Add child to this node

void
removeChild(NodeInterface $child)

Remove a specific child

void
setSibling(NodeInterface $sibling, bool $right = true)

Function to set the left or right sibling of a node

Details

NodeInterface[] getChildren(bool $recursive = false)

Since: 4.0.0

Get the children of this node

Parameters

bool $recursive

False by default

Return Value

NodeInterface[]

The children

NodeInterface|null getParent()

Since: 4.0.0

Get the parent of this node

Return Value

NodeInterface|null

ImmutableNodeInterface getRoot()

Since: 4.0.0

Get the root of the tree

Return Value

ImmutableNodeInterface

bool hasChildren()

Since: 4.0.0

Test if this node has children

Return Value

bool

True if there is a child

bool hasParent()

Since: 4.0.0

Test if this node has a parent

Return Value

bool

True if there is a parent

NodeInterface|null getSibling(bool $right = true)

Since: 4.0.0

Returns the right or left sibling of a node

Parameters

bool $right

If set to false, returns the left sibling

Return Value

NodeInterface|null

NodeInterface object of the sibling.

void setParent(NodeInterface $parent)

Since: 4.0.0

Set the parent of this node

If the node already has a parent, the link is unset

Parameters

NodeInterface $parent

NodeInterface for the parent to be set

Return Value

void

void addChild(NodeInterface $child)

Since: 4.0.0

Add child to this node

If the child already has a parent, the link is unset

Parameters

NodeInterface $child

The child to be added.

Return Value

void

void removeChild(NodeInterface $child)

Since: 4.0.0

Remove a specific child

Parameters

NodeInterface $child

Child to remove

Return Value

void

void setSibling(NodeInterface $sibling, bool $right = true)

Since: 4.0.0

Function to set the left or right sibling of a node

Parameters

NodeInterface $sibling

NodeInterface object for the sibling

bool $right

If set to false, the sibling is the left one

Return Value

void