/** * Gets a relative filesystem path based on the repository path, AND * creates the file on the filesystem if it's in the repository * and not yet on the filesystem. * The repository path points to a nt-resource node, whose title * should be the filename, and which has a child+property * jcr:content/jcr:data where the file data is stored. * * @param string $path path to the nt-resource node. * @return string with a path to the file, relative to the web directory. */ public function getUrl(NodeInterface $node) { $hasData = false; if ($node->hasNode('jcr:content')) { $contentNode = $node->getNode('jcr:content'); if ($contentNode->hasProperty('jcr:data')) { $hasData = true; } } if (!$hasData) { //TODO: notfound exception is not appropriate ... how to best do this? //throw new NotFoundHttpException('no picture found at ' . $node->getPath()); return 'notfound'; } $path = $node->getPath(); $relativePath = $this->pathMapper->getUrl($path); $fullPath = $this->fileBasePath . $relativePath . $this->getExtension($contentNode); if (!file_exists($fullPath)) { try { $this->saveData($contentNode, $fullPath); } catch (Imagine\Exception\Exception $e) { //TODO: notfound exception is not appropriate ... how to best do this? //throw new NotFoundHttpException('image save to filesystem failed: ' . $e->getMessage()); return 'notfound'; } } return $this->webRelativePath . $relativePath . $this->getExtension($contentNode); }
public function setUp() { $this->dm = $this->createDocumentManager(array(__DIR__)); $repository = $this->dm->getPhpcrSession()->getRepository(); if (!$repository->getDescriptor('node.type.management.orderable.child.nodes.supported')) { $this->markTestSkipped('PHPCR repository doesn\'t support orderable child nodes'); } $this->node = $this->resetFunctionalNode($this->dm); $parent = $this->dm->find(null, $this->node->getPath()); $node1 = new Generic(); $node1->setParentDocument($parent); $node1->setNodename('source'); $this->dm->persist($node1); $this->childrenNames = array('first', 'second', 'third', 'fourth'); foreach ($this->childrenNames as $childName) { $child = new Generic(); $child->setNodename($childName); $child->setParentDocument($node1); $this->dm->persist($child); } $node2 = new Generic(); $node2->setNodename('target'); $node2->setParentDocument($parent); $this->dm->persist($node2); $this->dm->flush(); $this->dm->clear(); }
protected function toJsonLD(NodeInterface $node) { $data = $node->getPropertiesValues(null, false); $data['@'] = $node->getPath(); $data['a'] = $node->getPrimaryNodeType(); return $data; }
/** * Traverse the node * * @param NodeInterface|null $node The node to traverse, if it exists yet * @param array $segments The element => token stack * @param array $result The result * * @return null */ private function traverse(array $segments, &$result = array(), $node = null) { $path = array(); if (null !== $node) { $path = explode('/', substr($node->getPath(), 1)); } do { list($element, $bitmask) = array_shift($segments); if ($bitmask & SelectorParser::T_STATIC) { $path[] = $element; if ($bitmask & SelectorParser::T_LAST) { if ($node = $this->getNode($path)) { $result[] = $node; break; } } } if ($bitmask & SelectorParser::T_PATTERN) { if (null === ($parentNode = $this->getNode($path))) { return; } $children = $this->getChildren($parentNode, $element); foreach ($children as $child) { if ($bitmask & SelectorParser::T_LAST) { $result[] = $child; } else { $this->traverse($segments, $result, $child); } } return; } } while ($segments); }
public function setUp() { $this->typeReference = 'Doctrine\\Tests\\ODM\\PHPCR\\Functional\\Versioning\\ReferenceTestObj'; $this->dm = $this->createDocumentManager(); // Check that the repository supports versioning $repository = $this->dm->getPhpcrSession()->getRepository(); if (!$repository->getDescriptor('option.versioning.supported')) { $this->markTestSkipped('PHPCR repository does not support versioning'); } $this->node = $this->resetFunctionalNode($this->dm); $versionNode = $this->node->addNode('versionTestObj'); $versionNode->setProperty('username', 'lsmith'); $versionNode->setProperty('numbers', array(3, 1, 2)); $versionNode->setProperty('phpcr:class', $this->typeVersion); $versionNode->addMixin("mix:versionable"); $referenceNode = $this->node->addNode('referenceTestObj'); $referenceNode->setProperty('content', 'reference test'); $referenceNode->setProperty('phpcr:class', $this->typeReference); $referenceNode->addMixin("mix:referenceable"); $this->dm->getPhpcrSession()->save(); $versionNodeWithReference = $this->node->addNode('versionTestObjWithReference'); $versionNodeWithReference->setProperty('username', 'laupifrpar'); $versionNodeWithReference->setProperty('numbers', array(6, 4, 5)); $versionNodeWithReference->setProperty('reference', $referenceNode); $versionNodeWithReference->addMixin("mix:versionable"); $this->dm->getPhpcrSession()->save(); $this->dm = $this->createDocumentManager(); }
/** * {@inheritdoc} */ public function remove(NodeInterface $node, PropertyInterface $property, $webspaceKey, $languageCode, $segmentKey) { // if exist remove property of node if ($node->hasProperty($property->getName())) { $node->getProperty($property->getName())->remove(); } }
/** * @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; }
/** * {@inheritdoc} */ protected function initialize() { if (true === $this->initialized) { return; } $this->documents = $this->parentNode->getNodes(); $this->initialized = true; }
/** * * * @param NodeInterface $contentNode * @param string $filesystemPath * @return Boolean */ protected function saveData($contentNode, $filesystemPath) { $data = $contentNode->getProperty('jcr:data')->getString(); $dirname = dirname($filesystemPath); if (!file_exists($dirname)) { mkdir($dirname, 0755, true); } return file_put_contents($filesystemPath, $data); }
/** * 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); } }
/** * {@inheritDoc} */ public function writeMetadata(DocumentManagerInterface $dm, NodeInterface $node, $className) { $className = $this->expandClassName($dm, $className); if ('Doctrine\\ODM\\PHPCR\\Document\\Generic' !== $className) { $node->setProperty('phpcr:class', $className, PropertyType::STRING); $class = $dm->getClassMetadata($className); $node->setProperty('phpcr:classparents', $class->getParentClasses(), PropertyType::STRING); } }
/** * {@inheritdoc} */ public function write(NodeInterface $node, PropertyInterface $property, $userId, $webspaceKey, $languageCode, $segmentKey) { $value = $property->getValue(); if ($value !== null) { $node->setProperty($property->getName(), $this->removeValidation($this->removeIllegalCharacters($value))); } else { $this->remove($node, $property, $webspaceKey, $languageCode, $segmentKey); } }
/** * {@inheritdoc} */ public function write(NodeInterface $node, PropertyInterface $property, $userId, $webspaceKey, $languageCode, $segmentKey) { $value = $property->getValue(); if ($value !== null && $value !== false && $value !== 'false' && $value !== '') { $node->setProperty($property->getName(), true); } else { $node->setProperty($property->getName(), false); } }
protected function createNodes(NodeInterface $parentNode, $number, $properties = array(), $offset = 0) { $number = $number + $offset; for ($i = $offset; $i < $number; $i++) { $node = $parentNode->addNode('node-' . $i); foreach ($properties as $property => $value) { $node->setProperty($property, $value); } } }
private function traverse(NodeInterface $node) { $i = 10; foreach ($node->getNodes() as $childNode) { $childNode->setProperty(NodeOrderSubscriber::SULU_ORDER, $i); $this->context->getOutput()->writeln(sprintf('<info>[+]</info> Setting order "<comment>%s</comment>" on <comment>%s</comment>', $i, $childNode->getPath())); $this->traverse($childNode); $i += 10; } }
/** * Transform a node into a uuid * * @param \PHPCR\NodeInterface|null $node * * @return string|null the uuid to the node or null if $node is null * * @throws UnexpectedTypeException if given value is not a PHPCR\NodeInterface */ public function transform($node) { if (null === $node) { return null; } if (!$node instanceof NodeInterface) { throw new UnexpectedTypeException($node, 'PHPCR\\NodeInterface'); } return $node->getIdentifier(); }
protected function getTranslationNode(NodeInterface $parentNode, $locale) { $name = Translation::LOCALE_NAMESPACE . ":{$locale}"; if (!$parentNode->hasNode($name)) { $node = $parentNode->addNode($name); } else { $node = $parentNode->getNode($name); } return $node; }
public function setUp() { $this->type = 'Doctrine\\Tests\\Models\\CMS\\CmsUser'; $this->dm = $this->createDocumentManager(array(__DIR__)); $this->node = $this->resetFunctionalNode($this->dm); $user = $this->node->addNode('lsmith'); $user->setProperty('username', 'lsmith'); $user->setProperty('numbers', array(3, 1, 2)); $user->setProperty('phpcr:class', $this->type, \PHPCR\PropertyType::STRING); $this->dm->getPhpcrSession()->save(); }
/** * {@inheritdoc} */ public function read(NodeInterface $node, PropertyInterface $property, $webspaceKey, $languageCode, $segmentKey) { $value = ''; if ($node->hasProperty($property->getName())) { /** @var \DateTime $propertyValue */ $propertyValue = $node->getPropertyValue($property->getName()); $value = $propertyValue->format('Y-m-d'); } $property->setValue($value); return $value; }
public function it_should_provide_a_method_to_determine_if_a_node_is_versionable(NodeInterface $nodeVersionable, NodeInterface $nodeNotVersionable, NodeTypeInterface $mixin1, NodeTypeInterface $mixin2) { $nodeVersionable->getMixinNodeTypes()->willReturn(array($mixin1, $mixin2)); $nodeNotVersionable->getMixinNodeTypes()->willReturn(array($mixin2)); $nodeNotVersionable->getPath()->willReturn('foobar'); $mixin1->getName()->willReturn('mix:versionable'); $this->assertNodeIsVersionable($nodeVersionable)->shouldReturn(null); try { $this->assertNodeIsVersionable($nodeNotVersionable); } catch (\OutOfBoundsException $e) { } }
/** * {@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 loadFixtures() { $contentMapperRequest = ContentMapperRequest::create()->setType(Structure::TYPE_SNIPPET)->setTemplateKey('animal')->setLocale('en')->setUserId(1)->setData(['title' => 'ElePHPant'])->setState(StructureInterface::STATE_PUBLISHED); $this->snippet1 = $this->contentMapper->saveRequest($contentMapperRequest); $contentMapperRequest = ContentMapperRequest::create()->setType(Structure::TYPE_SNIPPET)->setTemplateKey('animal')->setLocale('de')->setUserId(1)->setData(['title' => 'Penguin'])->setState(StructureInterface::STATE_PUBLISHED); $this->snippet2 = $this->contentMapper->saveRequest($contentMapperRequest); $this->snippet1Node = $this->session->getNodeByIdentifier($this->snippet1->getUuid()); $this->snippet1OriginalPath = $this->snippet1Node->getPath(); $contentMapperRequest = ContentMapperRequest::create()->setUuid($this->snippet1->getUuid())->setType(Structure::TYPE_SNIPPET)->setTemplateKey('animal')->setLocale('de')->setUserId(1)->setData(['title' => 'English ElePHPant'])->setState(StructureInterface::STATE_PUBLISHED); $this->contentMapper->saveRequest($contentMapperRequest); $contentMapperRequest = ContentMapperRequest::create()->setType(Structure::TYPE_SNIPPET)->setTemplateKey('animal')->setLocale('en')->setUserId(1)->setData(['title' => 'Some other animal'])->setState(StructureInterface::STATE_PUBLISHED); $this->contentMapper->saveRequest($contentMapperRequest); }
/** * {@inheritdoc} */ public function read(NodeInterface $node, PropertyInterface $property, $webspaceKey, $languageCode, $segmentKey) { $value = $this->defaultValue; if ($node->hasProperty($property->getName())) { $value = $node->getPropertyValue($property->getName()); } // the RedirectType subscriber sets the internal link as a reference if ($value instanceof NodeInterface) { $value = $value->getIdentifier(); } $property->setValue($value); return $value; }
/** * {@inheritdoc} */ public function resolveMetadataForNode(NodeInterface $node) { if (false === $node->hasProperty('jcr:mixinTypes')) { return; } $mixinTypes = (array) $node->getPropertyValue('jcr:mixinTypes'); foreach ($mixinTypes as $mixinType) { if (true == $this->metadataFactory->hasMetadataForPhpcrType($mixinType)) { return $this->metadataFactory->getMetadataForPhpcrType($mixinType); } } return; }
public function testCreateFromFile() { $parent = new FixPHPCR1TestObj(); $parent->id = '/functional/filetest'; $this->dm->persist($parent); $parent->file = new File(); $parent->file->setFileContentFromFilesystem(dirname(__FILE__) . '/_files/foo.txt'); $this->dm->flush(); $this->dm->clear(); $this->assertTrue($this->node->getNode('filetest')->hasNode('file')); $this->assertTrue($this->node->getNode('filetest')->getNode('file')->hasNode('jcr:content')); $this->assertTrue($this->node->getNode('filetest')->getNode('file')->getNode('jcr:content')->hasProperty('jcr:data')); }
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); } }
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']]); }
public function setUp() { $this->type = 'Doctrine\\Tests\\ODM\\PHPCR\\Functional\\TypeUser'; $this->dm = $this->createDocumentManager(array(__DIR__)); $this->node = $this->resetFunctionalNode($this->dm); $user = $this->node->addNode('user'); $user->setProperty('username', 'lsmith'); $user->setProperty('note', 'test'); $user->setProperty('numbers', array(3, 1, 2)); $user->setProperty('parameters', array('bar', 'dong')); $user->setProperty('parameterKey', array('foo', 'ding')); $user->setProperty('phpcr:class', $this->type, PropertyType::STRING); $this->dm->getPhpcrSession()->save(); }
public function testLoadWithoutData() { $content = []; $this->node->getPropertyValueWithDefault(Argument::any(), Argument::any())->will(function ($arguments) use(&$content) { if (isset($content[$arguments[0]])) { return $content[$arguments[0]]; } else { return $arguments[1]; } }); $this->extension->setLanguageCode('de', 'i18n', null); $result = $this->extension->load($this->node->reveal(), 'default', 'de'); $this->assertEquals(['title' => '', 'description' => '', 'keywords' => '', 'canonicalUrl' => '', 'noIndex' => false, 'noFollow' => false, 'hideInSitemap' => false], $result); }
private function walkNode(NodeBuilder $builder, NodeInterface $parentNode) { for ($i = $builder->getRangeStart(); $i <= $builder->getRangeEnd(); $i++) { $name = str_replace(NodeBuilder::ITERATION_TOKEN, $i, $builder->getName()); $this->count++; $node = $parentNode->addNode($name, $builder->getNodeTypeName()); foreach ($builder->getProperties() as $property) { list($name, $value, $type) = $property; $node->setProperty($name, $value, PropertyType::valueFromName($type)); } foreach ($builder->getNodes() as $childNodeBuilder) { $this->walkNode($childNodeBuilder, $node); } } }