protected function setUp() { parent::setUp(); $this->contentMapper = $this->prophesize('Sulu\\Component\\Content\\Mapper\\ContentMapperInterface'); $this->requestAnalyzer = $this->prophesize('Sulu\\Component\\Webspace\\Analyzer\\RequestAnalyzerInterface'); $this->contentTypeManager = $this->prophesize('Sulu\\Component\\Content\\ContentTypeManagerInterface'); $this->structureManager = $this->prophesize('Sulu\\Component\\Content\\Compat\\StructureManagerInterface'); $this->sessionManager = $this->prophesize('Sulu\\Component\\PHPCR\\SessionManager\\SessionManagerInterface'); $this->session = $this->prophesize('PHPCR\\SessionInterface'); $this->node = $this->prophesize('PHPCR\\NodeInterface'); $this->parentNode = $this->prophesize('PHPCR\\NodeInterface'); $this->startPageNode = $this->prophesize('PHPCR\\NodeInterface'); $webspace = new Webspace(); $webspace->setKey('sulu_test'); $locale = new Localization(); $locale->setCountry('us'); $locale->setLanguage('en'); $this->requestAnalyzer->getWebspace()->willReturn($webspace); $this->requestAnalyzer->getCurrentLocalization()->willReturn($locale); $this->contentTypeManager->get('text_line')->willReturn(new TextLine('')); $this->sessionManager->getSession()->willReturn($this->session->reveal()); $this->sessionManager->getContentNode('sulu_test')->willReturn($this->startPageNode->reveal()); $this->session->getNodeByIdentifier('123-123-123')->willReturn($this->node->reveal()); $this->session->getNodeByIdentifier('321-321-321')->willReturn($this->parentNode->reveal()); $this->node->getIdentifier()->willReturn('123-123-123'); $this->node->getParent()->willReturn($this->parentNode->reveal()); $this->node->getDepth()->willReturn(4); $this->parentNode->getIdentifier()->willReturn('321-321-321'); $this->parentNode->getDepth()->willReturn(3); $this->startPageNode->getDepth()->willReturn(3); $this->structureResolver = new StructureResolver($this->contentTypeManager->reveal(), $this->structureManager->reveal()); }
/** * Let the visitor visit the ancestors from root node according to mapper * down to the parent of the node identified by url * * @param string $url the url (without eventual prefix from routing config) * @param ItemVisitorInterface $visitor the visitor to look at the nodes */ public function visitAncestors($url, ItemVisitorInterface $visitor) { $node = $this->session->getNode($this->mapper->getStorageId($url)); $i = $this->rootnode->getDepth(); while (($ancestor = $node->getAncestor($i++)) != $node) { $ancestor->accept($visitor); } }
/** * Recursively output node and all its children into the file in the system * view format * * @param NodeInterface $node the node to output * @param resource $stream The stream resource (i.e. acquired with fopen) to * which the XML serialization of the subgraph will be output. Must * support the fwrite method. * @param boolean $skipBinary A boolean governing whether binary properties * are to be serialized. * @param boolean $noRecurse A boolean governing whether the subgraph at * absPath is to be recursed. * @param boolean $root Whether this is the root node of the resulting * document, meaning the namespace declarations have to be included in * it. */ private static function exportSystemViewRecursive(NodeInterface $node, NamespaceRegistryInterface $ns, $stream, $skipBinary, $noRecurse, $root = false) { fwrite($stream, '<sv:node'); if ($root) { self::exportNamespaceDeclarations($ns, $stream); } fwrite($stream, ' sv:name="' . (0 === $node->getDepth() ? 'jcr:root' : htmlspecialchars($node->getName())) . '">'); // the order MUST be primary type, then mixins, if any, then jcr:uuid if its a referenceable node fwrite($stream, '<sv:property sv:name="jcr:primaryType" sv:type="Name"><sv:value>' . htmlspecialchars($node->getPropertyValue('jcr:primaryType')) . '</sv:value></sv:property>'); if ($node->hasProperty('jcr:mixinTypes')) { fwrite($stream, '<sv:property sv:name="jcr:mixinTypes" sv:type="Name" sv:multiple="true">'); foreach ($node->getPropertyValue('jcr:mixinTypes') as $type) { fwrite($stream, '<sv:value>' . htmlspecialchars($type) . '</sv:value>'); } fwrite($stream, '</sv:property>'); } if ($node->isNodeType('mix:referenceable')) { fwrite($stream, '<sv:property sv:name="jcr:uuid" sv:type="String"><sv:value>' . $node->getIdentifier() . '</sv:value></sv:property>'); } foreach ($node->getProperties() as $name => $property) { /** @var $property \PHPCR\PropertyInterface */ if ($name == 'jcr:primaryType' || $name == 'jcr:mixinTypes' || $name == 'jcr:uuid') { // explicitly handled before continue; } if (PropertyType::BINARY == $property->getType() && $skipBinary) { // do not output binary data in the xml continue; } fwrite($stream, '<sv:property sv:name="' . htmlentities($name) . '" sv:type="' . PropertyType::nameFromValue($property->getType()) . '"' . ($property->isMultiple() ? ' sv:multiple="true"' : '') . '>'); $values = $property->isMultiple() ? $property->getString() : array($property->getString()); foreach ($values as $value) { if (PropertyType::BINARY == $property->getType()) { $val = base64_encode($value); } else { $val = htmlspecialchars($value); //TODO: can we still have invalid characters after this? if so base64 and property, xsi:type="xsd:base64Binary" } fwrite($stream, "<sv:value>{$val}</sv:value>"); } fwrite($stream, "</sv:property>"); } if (!$noRecurse) { foreach ($node as $child) { if (!($child->getDepth() == 1 && NodeHelper::isSystemItem($child))) { self::exportSystemViewRecursive($child, $ns, $stream, $skipBinary, $noRecurse); } } } fwrite($stream, '</sv:node>'); }
/** * {@inheritdoc} */ public function getDepth() { return $this->node->getDepth(); }
/** * Gather the parent and all child mappings so they can be fetched in one * go. * * @param ClassMetadata $class The metadata about the document to know what to do. * @param NodeInterface $node The node to prefetch parent and childs for. * @param string|null $locale The locale to also prefetch the translation * child if applicable. * * @return array List of absolute paths to nodes that should be prefetched. */ public function collectPrefetchHierarchy(ClassMetadata $class, NodeInterface $node, $locale = null) { $prefetch = array(); if ($class->parentMapping && $node->getDepth() > 0) { $prefetch[] = PathHelper::getParentPath($node->getPath()); } foreach ($class->childMappings as $fieldName) { $childName = $class->mappings[$fieldName]['nodeName']; $prefetch[] = PathHelper::absolutizePath($childName, $node->getPath()); } if ($locale && count($prefetch) && 'child' === $class->translator) { $prefetch[] = $node->getPath() . '/phpcr_locale:' . $locale; } return $prefetch; }
public function testGetDepth() { $this->assertEquals(1, $this->node->getDepth()); $this->assertEquals(3, $this->deepnode->getDepth()); }