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