- var_dump: documentation ( source)
- time: documentation ( source)
- rand: documentation ( source)
- md5: documentation ( source)
<?php
interface NodeInterface
{
public function addNode(Node $node);
public function isLeaf();
public function isNode();
public function getKey();
public function setKey($key);
public function getValue();
public function setValue($value);
public function getUid();
public function uid();
public function key();
public function value();
}
class ArrComp implements NodeInterface
{
protected $uid;
protected $nodes;
protected $value;
public function __construct($key = null, $value = null)
{
$this->uid = rand(0, 9) . md5(rand(10, 99) . time() . rand(100, 999)) . rand(1000, 9999);
$this->value = new stdClass;
$this->value->key = $key;
$this->value->val = $value;
$this->nodes = [];
}
public function addNode(Node $node)
{
$this->nodes[] = $node;
return $this;
}
public function isLeaf()
{
return count($this->nodes) == 0;
}
public function isNode()
{
return count($this->nodes) > 0;
}
public function getKey()
{
return $this->value->key;
}
public function key()
{
return $this->value->key;
}
public function setKey($key = null)
{
$this->value->key = $key;
return $this;
}
public function getValue()
{
return $this->value->val;
}
public function value()
{
return $this->value->val;
}
public function setValue($value = null)
{
$this->value->val = $value;
return $this;
}
public function getUid()
{
return $this->uid;
}
public function uid()
{
return $this->uid;
}
}
$comp = new ArrComp('pk');
var_dump($comp);