File: D:/HostingSpaces/SBogers85/equichecker.com/app/KommaApp/Tree/TreeNode.php
<?php
namespace KommaApp\Tree;
class TreeNode
{
public $parent = null;
public $children = [];
public $attributes;
public function __construct($data, &$parent = null)
{
$this->attributes = $data;
$this->parent = $parent;
}
/**
* @param HierarchicalEntity $hierarchicalEntity
*/
public function addChild(TreeNode $hierarchicalEntity)
{
$this->children[] = $hierarchicalEntity;
}
public function hasChildren()
{
return count($this->children) > 0;
}
public function getParent()
{
if($this->parent != null) return $this->parent;
return false;
}
/*
* Return f.e. $this->attributes['name'] as $this->name
*/
public function __get($name)
{
if (array_key_exists($name, $this->attributes)) {
return $this->attributes[$name];
}
return null;
}
/*
* If we don't have this function the empty() method
* doesn't work nice with the __get magic method.
*/
public function __isset($key){
if(null===$this->__get($key)){
return false;
}
return true;
}
}