HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/vebon.komma.pro/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;
    }
}