2015-02-06 11:23:07 -05:00
|
|
|
<?php
|
2016-02-08 09:41:00 -05:00
|
|
|
/* Icinga Web 2 | (c) 2015 Icinga Development Team | GPLv2+ */
|
2015-02-06 11:23:07 -05:00
|
|
|
|
|
|
|
|
namespace Icinga\Data\Tree;
|
|
|
|
|
|
|
|
|
|
use ArrayIterator;
|
|
|
|
|
use RecursiveIterator;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Iterator over a tree node's children
|
|
|
|
|
*/
|
|
|
|
|
class TreeNodeIterator implements RecursiveIterator
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* The node's children
|
|
|
|
|
*
|
2015-03-12 08:39:17 -04:00
|
|
|
* @var array
|
2015-02-06 11:23:07 -05:00
|
|
|
*/
|
|
|
|
|
protected $children;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a new iterator over a tree node's children
|
|
|
|
|
*
|
2015-02-06 11:27:14 -05:00
|
|
|
* @param TreeNode $node
|
2015-02-06 11:23:07 -05:00
|
|
|
*/
|
2015-02-06 11:27:14 -05:00
|
|
|
public function __construct(TreeNode $node)
|
2015-02-06 11:23:07 -05:00
|
|
|
{
|
|
|
|
|
$this->children = new ArrayIterator($node->getChildren());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-02-10 10:59:43 -05:00
|
|
|
* {@inheritdoc}
|
2015-02-06 11:23:07 -05:00
|
|
|
*/
|
|
|
|
|
public function current()
|
|
|
|
|
{
|
|
|
|
|
return $this->children->current();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-02-10 10:59:43 -05:00
|
|
|
* {@inheritdoc}
|
2015-02-06 11:23:07 -05:00
|
|
|
*/
|
|
|
|
|
public function key()
|
|
|
|
|
{
|
|
|
|
|
return $this->children->key();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-02-10 10:59:43 -05:00
|
|
|
* {@inheritdoc}
|
2015-02-06 11:23:07 -05:00
|
|
|
*/
|
|
|
|
|
public function next()
|
|
|
|
|
{
|
|
|
|
|
$this->children->next();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-02-10 10:59:43 -05:00
|
|
|
* {@inheritdoc}
|
2015-02-06 11:23:07 -05:00
|
|
|
*/
|
|
|
|
|
public function rewind()
|
|
|
|
|
{
|
|
|
|
|
$this->children->rewind();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-02-10 10:59:43 -05:00
|
|
|
* {@inheritdoc}
|
2015-02-06 11:23:07 -05:00
|
|
|
*/
|
|
|
|
|
public function valid()
|
|
|
|
|
{
|
|
|
|
|
return $this->children->valid();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-02-10 10:59:43 -05:00
|
|
|
* {@inheritdoc}
|
2015-02-06 11:23:07 -05:00
|
|
|
*/
|
|
|
|
|
public function hasChildren()
|
|
|
|
|
{
|
|
|
|
|
return $this->current()->hasChildren();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-02-10 10:59:43 -05:00
|
|
|
* {@inheritdoc}
|
|
|
|
|
* @return TreeNodeIterator
|
2015-02-06 11:23:07 -05:00
|
|
|
*/
|
|
|
|
|
public function getChildren()
|
|
|
|
|
{
|
|
|
|
|
return new static($this->current());
|
|
|
|
|
}
|
2015-12-21 05:09:20 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get whether the iterator is empty
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function isEmpty()
|
|
|
|
|
{
|
2016-03-30 09:27:34 -04:00
|
|
|
return ! $this->children->count();
|
2015-12-21 05:09:20 -05:00
|
|
|
}
|
2015-02-06 11:23:07 -05:00
|
|
|
}
|