/** * Print information about the visited node. * * @param ItemInterface $item the node to visit */ public function visit(ItemInterface $item) { if (!$item instanceof NodeInterface) { throw new \Exception("Internal error: did not expect to visit a non-node object: {$item}"); } if ($item->getDepth() == 0) { $name = 'ROOT'; } elseif ($this->showFullPath) { $name = $item->getPath(); } else { $name = $item->getName(); } $out = str_repeat(' ', $this->level) . '<comment>' . $name . '</comment>'; if ($this->identifiers) { $identifier = $item->getIdentifier(); if ($identifier) { $out .= "({$identifier})"; } } $out .= ':'; $this->output->writeln($out); }
/** * Determine whether this item is to be considered a system item that you * usually want to hide and that should not be removed when purging the * repository. * * @param ItemInterface $item * * @return boolean true if $item is a system item, false otherwise */ public static function isSystemItem(ItemInterface $item) { if ($item->getDepth() > 1) { return false; } $name = $item->getName(); return strpos($name, 'jcr:') === 0 || strpos($name, 'rep:') === 0; }
/** * Called when the Visitor is passed to an Item. * * It calls TraversingItemVisitor::entering() followed by * TraversingItemVisitor::leaving(). Implement these abstract methods to * specify behavior on 'arrival at' and 'after leaving' the $item. * * If this method throws, the visiting process is aborted. * * @param ItemInterface $item the Node or Property that is accepting * this visitor. * * @throws RepositoryException if an error occurs. * * @api */ public function visit(ItemInterface $item) { if ($this->currentDepth == 0) { $this->currentDepth = $item->getDepth(); } if ($item instanceof PropertyInterface) { $this->entering($item, $this->currentDepth); $this->leaving($item, $this->currentDepth); } else { /** @var $item NodeInterface */ try { if ($this->breadthFirst === false) { $this->entering($item, $this->currentDepth); if ($this->maxDepth == -1 || $this->currentDepth < $this->maxDepth) { $this->currentDepth++; foreach ($item->getProperties() as $property) { /** @var $property PropertyInterface */ $property->accept($this); } foreach ($item->getNodes() as $node) { /** @var $node NodeInterface */ $node->accept($this); } $this->currentDepth--; } $this->leaving($item, $this->currentDepth); } else { $this->entering($item, $this->currentDepth); $this->leaving($item, $this->currentDepth); if ($this->maxDepth == -1 || $this->currentDepth < $this->maxDepth) { foreach ($item->getProperties() as $property) { /** @var $property PropertyInterface */ $property->accept($this); } foreach ($item->getNodes() as $node) { /** @var $node NodeInterface */ $node->accept($this); } } while (!$this->currentQueue->isEmpty() || !$this->nextQueue->isEmpty()) { if ($this->currentQueue->isEmpty()) { $this->currentDepth++; $this->currentQueue = $this->nextQueue; $this->nextQueue = new SplQueue(); } $item = $this->currentQueue->dequeue(); $item->accept($this); } $this->currentDepth = 0; } } catch (RepositoryException $exception) { $this->currentDepth = 0; throw $exception; } } }