Archived
1
0
Fork 0

initial commit

This commit is contained in:
Henrik Hautakoski 2017-09-01 17:10:27 +02:00
commit e869a1cab4
107 changed files with 9029 additions and 0 deletions

View file

@ -0,0 +1,82 @@
<?php
namespace Navigation;
class Container
{
/**
* Children
*
* @var array
*/
protected $_children = array();
/**
* @return array
*/
public function getChildren()
{
return $this->_children;
}
/**
* @return bool
*/
public function hasChildren()
{
return empty($this->getChildren()) === false;
}
/**
* @param $child
* @return Node
*/
public function addChild($child)
{
if (is_array($child)) {
$node = new Node();
foreach($child as $k => $v) {
if ($k == 'children') {
continue;
}
$node->{'set' . ucfirst($k)}($v);
}
if (isset($child['children'])) {
foreach($child['children'] as $c_data) {
$node->addChild($c_data);
}
}
$child = $node;
}
if (!($child instanceof Node)) {
throw new Exception('Must be of type node.');
}
$this->_children[] = $child;
$child->setParent($this);
return $this;
}
/**
* @param $children
* @return Node
*/
public function addChildren($children)
{
foreach($children as $child) {
$this->addChild($child);
}
return $this;
}
}