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
|
|
|
|
|
*
|
2023-08-15 03:46:39 -04:00
|
|
|
* @var ArrayIterator
|
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());
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-18 10:35:08 -05:00
|
|
|
public function current(): TreeNode
|
2015-02-06 11:23:07 -05:00
|
|
|
{
|
|
|
|
|
return $this->children->current();
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-18 10:35:08 -05:00
|
|
|
public function key(): int
|
2015-02-06 11:23:07 -05:00
|
|
|
{
|
|
|
|
|
return $this->children->key();
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-18 10:35:08 -05:00
|
|
|
public function next(): void
|
2015-02-06 11:23:07 -05:00
|
|
|
{
|
|
|
|
|
$this->children->next();
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-18 10:35:08 -05:00
|
|
|
public function rewind(): void
|
2015-02-06 11:23:07 -05:00
|
|
|
{
|
|
|
|
|
$this->children->rewind();
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-18 10:35:08 -05:00
|
|
|
public function valid(): bool
|
2015-02-06 11:23:07 -05:00
|
|
|
{
|
|
|
|
|
return $this->children->valid();
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-18 10:35:08 -05:00
|
|
|
public function hasChildren(): bool
|
2015-02-06 11:23:07 -05:00
|
|
|
{
|
|
|
|
|
return $this->current()->hasChildren();
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-18 10:35:08 -05:00
|
|
|
public function getChildren(): TreeNodeIterator
|
2015-02-06 11:23:07 -05:00
|
|
|
{
|
|
|
|
|
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
|
|
|
}
|