/** * @param INode $node * @param callable $callback */ public function __construct(INode $node, callable $callback = null) { $this->node = $node; $this->callback = $callback ?: function (INode $node) { return $node->getGuid(); }; }
public function match(INode $node) { if ($this->path === '*') { return true; } else { if ($this->path === $node->getName()) { return true; } } return false; }
protected function walk(array $array, INode $root) { foreach ($array as $k => $v) { $root->addNode($node = new Node($k)); if (!is_array($v)) { $node->setValue($v); continue; } $this->walk($v, $node); } }
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))); }
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(); } }
public function onTextEvent(TextEvent $textEvent) { if ($this->valueNode === null) { $this->current->setValue($textEvent->getText()); return; } if (($text = trim($textEvent->getText())) != '' || $this->stripEmpty === false) { $this->current->addNode($this->createNode($this->valueNode, [], $textEvent->getText())); } }