initial commit
This commit is contained in:
commit
e869a1cab4
107 changed files with 9029 additions and 0 deletions
82
app/library/Navigation/Container.php
Normal file
82
app/library/Navigation/Container.php
Normal 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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in a new issue