/** * @param JsonSerializationVisitor $visitor * @param NodeInterface $nodeInterface * @param array $type * @param Context $context */ public function serializePhpcrNode(JsonSerializationVisitor $visitor, NodeInterface $node, array $type, Context $context) { $res = array(); foreach ($node->getProperties() as $name => $property) { $res[$name] = $property->getValue(); } return $res; }
/** * Removes non translated properties. * * @param NodeInterface $node */ private function upgradeNode(NodeInterface $node) { foreach ($node->getProperties('i18n:-*') as $property) { $property->remove(); } foreach ($node->getNodes() as $childNode) { $this->upgradeNode($childNode); } }
public function testGetPropertiesNameGlobs() { $iterator = $this->node->getProperties(array('jcr:cr*', 'jcr:prim*')); $this->assertInstanceOf('Iterator', $iterator); $props = array(); foreach ($iterator as $prop) { array_push($props, $prop->getName()); } $this->assertContains('jcr:created', $props); $this->assertContains('jcr:primaryType', $props); }
/** * {@inheritdoc} */ public function getLocalesFor($document, NodeInterface $node, ClassMetadata $metadata) { $locales = array(); foreach ($node->getProperties("*{$this->prefix}*") as $prop) { $matches = null; if (preg_match('/' . $this->prefix . ':(..)-[^-]*/', $prop->getName(), $matches)) { if (is_array($matches) && count($matches) > 1 && !in_array($matches[1], $locales)) { $locales[] = $matches[1]; } } } return $locales; }
public function it_can_normalize_a_node_to_an_array(NodeInterface $node, PropertyInterface $p1, PropertyInterface $p2, PropertyInterface $p3) { $node->getProperties()->willReturn([$p1, $p2, $p3]); $p1->getName()->willReturn('my:property.1'); $p1->getType()->willReturn(PropertyType::STRING); $p1->getValue()->willReturn('P1 Val'); $p2->getName()->willReturn('my:property.2'); $p2->getType()->willReturn(PropertyType::DOUBLE); $p2->getValue()->willReturn('P2 Val'); $p3->getName()->willReturn('my:property.3'); $p3->getType()->willReturn(PropertyType::STRING); $p3->getValue()->willReturn('P3 Val'); $this->normalize($node)->shouldReturn(['my:property.1' => ['type' => 'String', 'value' => 'P1 Val'], 'my:property.2' => ['type' => 'Double', 'value' => 'P2 Val'], 'my:property.3' => ['type' => 'String', 'value' => 'P3 Val']]); }
private function traverse(NodeInterface $node, $readProperties = false) { if ($readProperties) { foreach ($node->getProperties() as $property) { try { $property->getValue(); } catch (\PHPCR\RepositoryException $e) { } } } foreach ($node->getNodes() as $child) { $this->traverse($child, $readProperties); } }
/** * Sets the workflowstage and the published date for the given node and all of its children to test resp. null. This * is done for every language in which the given properties exist. * * @param NodeInterface $node */ private function setNodeWorkflowStageToTestForCopy(NodeInterface $node) { $workflowStageNameFilter = $this->propertyEncoder->localizedSystemName(self::WORKFLOW_STAGE_FIELD, '*'); foreach ($node->getProperties($workflowStageNameFilter) as $property) { /** @var PropertyInterface $property */ $property->setValue(WorkflowStage::TEST); } $publishedNameFilter = $this->propertyEncoder->localizedSystemName(self::PUBLISHED_FIELD, '*'); foreach ($node->getProperties($publishedNameFilter) as $property) { /** @var PropertyInterface $property */ $property->setValue(null); } foreach ($node->getNodes() as $node) { /** @var NodeInterface $node */ $this->setNodeWorkflowStageToTestForCopy($node); } }
/** * {@inheritdoc} */ public function remove(NodeInterface $node, PropertyInterface $property, $webspaceKey, $languageCode, $segmentKey) { foreach ($node->getProperties($property->getName() . '-*') as $nodeProperty) { $node->getProperty($nodeProperty->getName())->remove(); } }
/** * Return all the localized values of the localized property indicated * by $name. * * @param NodeInterface $node * @param string $name Name of localized property */ public function getLocalizedPropertyValues(NodeInterface $node, $name) { $values = []; foreach ($node->getProperties() as $property) { /* @var PropertyInterface $property */ preg_match('/^' . $this->languageNamespace . ':([a-zA-Z_]*?)-' . $name . '/', $property->getName(), $matches); if ($matches) { $values[$matches[1]] = $property->getValue(); } } return $values; }
/** * Recursively output node and all its children into the file in the * document view format * * @param NodeInterface $node the node to output * @param NamespaceRegistryInterface $ns The namespace registry to export namespaces too * @param resource $stream the resource to write data out to * @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 exportDocumentViewRecursive(NodeInterface $node, NamespaceRegistryInterface $ns, $stream, $skipBinary, $noRecurse, $root = false) { $nodename = self::escapeXmlName($node->getName()); fwrite($stream, "<{$nodename}"); if ($root) { self::exportNamespaceDeclarations($ns, $stream); } foreach ($node->getProperties() as $name => $property) { /** @var $property \PHPCR\PropertyInterface */ if ($property->isMultiple()) { // skip multiple properties. jackrabbit does this too. cheap but whatever. use system view for a complete export continue; } if (PropertyType::BINARY == $property->getType()) { if ($skipBinary) { continue; } $value = base64_encode($property->getString()); } else { $value = htmlspecialchars($property->getString()); } fwrite($stream, ' ' . self::escapeXmlName($name) . '="' . $value . '"'); } if ($noRecurse || !$node->hasNodes()) { fwrite($stream, '/>'); } else { fwrite($stream, '>'); foreach ($node as $child) { if (!($child->getDepth() == 1 && NodeHelper::isSystemItem($child))) { self::exportDocumentViewRecursive($child, $ns, $stream, $skipBinary, $noRecurse); } } fwrite($stream, "</{$nodename}>"); } }
/** * Removes all localized properties in the given locale from the given node. * * @param NodeInterface $node * @param string $locale */ private function removeLocalizedNodeProperties(NodeInterface $node, $locale) { // remove all localized system properties from the node foreach ($node->getProperties($this->propertyEncoder->localizedSystemName('', $locale) . '*') as $property) { $property->remove(); } // remove all localized content properties from the node foreach ($node->getProperties($this->propertyEncoder->localizedContentName('', $locale) . '*') as $property) { $property->remove(); } }
/** * {@inheritdoc} */ public function getProperties($nameFilter = null) { return $this->node->getProperties($nameFilter); }
private function parsePhpcrNode(NodeInterface $node) { $this->parsePhpcrNodeProperties($node->getProperties()); }
public function formatNodePropertiesInline(NodeInterface $node) { $out = array(); foreach ($node->getProperties() as $property) { $out[] = sprintf('%s: %s', $property->getName(), $this->formatValue($property)); } return implode(', ', $out); }