mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-30 01:04:09 +02:00
lib: Add TreeIterator
This commit is contained in:
parent
040473f986
commit
9edaaa82e8
90
library/Icinga/Data/Tree/TreeIterator.php
Normal file
90
library/Icinga/Data/Tree/TreeIterator.php
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
<?php
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
|
||||||
|
namespace Icinga\Data\Tree;
|
||||||
|
|
||||||
|
//use RecursiveIterator;
|
||||||
|
//
|
||||||
|
//class TreeIterator implements RecursiveIterator
|
||||||
|
//{
|
||||||
|
// protected $position = 0;
|
||||||
|
//
|
||||||
|
// protected $nodes;
|
||||||
|
//
|
||||||
|
// public function __construct(NodeInterface $node)
|
||||||
|
// {
|
||||||
|
// $this->nodes = $node->getChildren();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public function hasChildren()
|
||||||
|
// {
|
||||||
|
// return $this->current()->hasChildren();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public function getChildren()
|
||||||
|
// {
|
||||||
|
// return new self($this->current());
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public function current()
|
||||||
|
// {
|
||||||
|
// return $this->nodes[$this->position];
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public function next()
|
||||||
|
// {
|
||||||
|
// ++$this->position;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public function valid()
|
||||||
|
// {
|
||||||
|
// return isset($this->nodes[$this->position]);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public function rewind()
|
||||||
|
// {
|
||||||
|
// $this->position = 0;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public function key()
|
||||||
|
// {
|
||||||
|
// return $this->position;
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
|
use ArrayIterator;
|
||||||
|
use RecursiveIterator;
|
||||||
|
|
||||||
|
class TreeIterator extends ArrayIterator implements RecursiveIterator
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Create a new TreeIterator
|
||||||
|
*
|
||||||
|
* @param NodeInterface $node
|
||||||
|
*/
|
||||||
|
public function __construct(NodeInterface $node)
|
||||||
|
{
|
||||||
|
parent::__construct($node->getChildren());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether an iterator can be created for the current node
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function hasChildren()
|
||||||
|
{
|
||||||
|
return $this->current()->hasChildren();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an iterator for the current node
|
||||||
|
*
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public function getChildren()
|
||||||
|
{
|
||||||
|
return new self($this->current());
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user