/** * @param IItem $item Start item */ public function __construct(IItem $item) { $current = $item->getParent(); if ($current) { // If root isn't the only item in structure // Until we get to the root item while ($current->getParent()) { $this->itemPath[] = $current; $current = $current->getParent(); } } $this->itemPath = array_reverse($this->itemPath); }
/** * @param IItem $item * @return null|IItem * @throws Component\Exception\Exception */ public function remove(IItem $item) { if (null === $item->getParent()) { throw new Exception('Root item can\'t be removed'); } $parent = $item->getParent(); $parent->removeChild($item); return $parent; }
/** * Checks if current position is valid * * @return bool */ public function valid() { return $this->current->getParent() !== null; }