예제 #1
0
 public function next()
 {
     $level = $this->node->getLevel() + 1;
     $pathCount = count($this->queryPathList) - 1;
     while (true) {
         if (!$this->iterator->valid()) {
             break;
         }
         /** @var $node INode */
         $node = $this->iterator->current();
         if ($node->getLevel() - $level === $pathCount) {
             $match = false;
             $pathIndex = $pathCount;
             while ($node && $node !== $this->node) {
                 if ($this->queryPathList[$pathIndex--]->match($node) === false) {
                     $match = false;
                     break;
                 }
                 $match = true;
                 $node = $node->getParent();
             }
             if ($match === true) {
                 break;
             }
         }
         $this->iterator->next();
     }
 }
예제 #2
0
 public function getPath(INode $node = null)
 {
     $current = $this;
     $path = [];
     if ($node && $node->getLevel() >= $this->getLevel()) {
         throw new NodeException(sprintf('Node [%s] is below current node [%s].', $node->getPath(), $this->getPath()));
     }
     while ($current || $node !== null && $current === $node) {
         $path[] = $current->getName();
         $current = $current->getParent();
     }
     return '/' . implode('/', array_reverse(array_filter($path)));
 }