Archived
1
0
Fork 0
This repository has been archived on 2026-04-03. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
httpcb/app/library/Navigation/Container.php
2023-04-30 16:57:42 +02:00

83 lines
1.5 KiB
PHP

<?php
namespace Httpcb\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 Container
* @throws Exception
*/
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 Container
* @throws Exception
*/
public function addChildren($children)
{
foreach ($children as $child) {
$this->addChild($child);
}
return $this;
}
}