本文整理汇总了PHP中PHPCR\SessionInterface::getNodeByIdentifier方法的典型用法代码示例。如果您正苦于以下问题:PHP SessionInterface::getNodeByIdentifier方法的具体用法?PHP SessionInterface::getNodeByIdentifier怎么用?PHP SessionInterface::getNodeByIdentifier使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPCR\SessionInterface
的用法示例。
在下文中一共展示了SessionInterface::getNodeByIdentifier方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadFixtures
public function loadFixtures()
{
$req = ContentMapperRequest::create()->setType(Structure::TYPE_SNIPPET)->setTemplateKey('animal')->setLocale('en')->setUserId(1)->setData(['title' => 'ElePHPant'])->setState(StructureInterface::STATE_PUBLISHED);
$this->snippet1 = $this->contentMapper->saveRequest($req);
$req = ContentMapperRequest::create()->setType(Structure::TYPE_SNIPPET)->setTemplateKey('animal')->setLocale('de')->setUserId(1)->setData(['title' => 'Penguin'])->setState(StructureInterface::STATE_PUBLISHED);
$this->snippet2 = $this->contentMapper->saveRequest($req);
$this->snippet1Node = $this->session->getNodeByIdentifier($this->snippet1->getUuid());
$this->snippet1OriginalPath = $this->snippet1Node->getPath();
$req = 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($req);
$req = ContentMapperRequest::create()->setType(Structure::TYPE_SNIPPET)->setTemplateKey('animal')->setLocale('en')->setUserId(1)->setData(['title' => 'Some other animal'])->setState(StructureInterface::STATE_PUBLISHED);
$this->contentMapper->saveRequest($req);
}
示例2: setUp
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());
}
示例3: findTranslation
/**
* {@inheritDoc}
*/
public function findTranslation($className, $id, $locale, $fallback = true)
{
try {
if (UUIDHelper::isUUID($id)) {
try {
$id = $this->session->getNodeByIdentifier($id)->getPath();
} catch (ItemNotFoundException $e) {
return null;
}
} elseif (strpos($id, '/') !== 0) {
$id = '/' . $id;
}
$document = $this->unitOfWork->getDocumentById($id);
if ($document) {
$this->unitOfWork->validateClassName($document, $className);
$class = $this->getClassMetadata(get_class($document));
$this->unitOfWork->doLoadTranslation($document, $class, $locale, $fallback);
return $document;
}
$node = $this->session->getNode($id);
} catch (PathNotFoundException $e) {
return null;
}
$hints = array('locale' => $locale, 'fallback' => $fallback);
return $this->unitOfWork->getOrCreateDocument($className, $node, $hints);
}
示例4: normalizeToPath
/**
* Normalize the given path or ID to a path.
*
* @param string $identifier
*
* @return string
*/
private function normalizeToPath($identifier)
{
if (UUIDHelper::isUUID($identifier)) {
$identifier = $this->session->getNodeByIdentifier($identifier)->getPath();
}
return $identifier;
}
示例5: findTranslation
/**
* Load the document from the content repository in the given language.
* If $fallback is set to true, then the language chooser strategy is used to load the best suited
* language for the translatable fields.
*
* If no translations can be found either using the fallback mechanism or not, an error is thrown.
*
* Note that this will be the same object as you got with a previous find/findTranslation call - we can't
* allow copies of objects to exist
*
* @param $className
* @param $id
* @param $locale The language to try to load
* @param bool $fallback Set to true if the language fallback mechanism should be used
* @return object
*/
public function findTranslation($className, $id, $locale, $fallback = true)
{
try {
$node = UUIDHelper::isUUID($id) ? $this->session->getNodeByIdentifier($id) : $this->session->getNode($id);
} catch (\PHPCR\PathNotFoundException $e) {
return null;
}
$hints = array('locale' => $locale, 'fallback' => $fallback);
return $this->unitOfWork->createDocument($className, $node, $hints);
}
示例6: onPostDeserialize
/**
* @param ObjectEvent $event
*/
public function onPostDeserialize(ObjectEvent $event)
{
$document = $event->getObject();
if (!$document instanceof PageDocument) {
return;
}
if (!$document->getUuid()) {
return;
}
try {
$node = $this->session->getNodeByIdentifier($document->getUuid());
} catch (ItemNotFoundException $e) {
return;
}
if ($this->registry->hasNode($node)) {
$registeredDocument = $this->registry->getDocumentForNode($node);
$this->registry->deregisterDocument($registeredDocument);
}
// TODO use the original locale somehow
$this->registry->registerDocument($document, $node, $document->getLocale());
}
示例7: testFindWithInternalLinkToItself
public function testFindWithInternalLinkToItself()
{
$this->initPhpcr();
$link = $this->createPage('test-1', 'de');
$page = $this->createInternalLinkPage('test-2', 'de', $link);
$node = $this->session->getNodeByIdentifier($page->getUuid());
$node->setProperty('i18n:de-internal_link', $node);
$this->session->save();
// should load content with requested node and not try to follow internal link
$result = $this->contentRepository->find($page->getUuid(), 'de', 'sulu_io', MappingBuilder::create()->addProperties(['title'])->getMapping());
$this->assertEquals($page->getUuid(), $result->getId());
$this->assertEquals('/test-2', $result->getPath());
$this->assertEquals('test-2', $result['title']);
}
示例8: migrateInternalLinks
private function migrateInternalLinks(SessionInterface $session, $directionUp = true)
{
$workspace = $session->getWorkspace();
$queryManager = $workspace->getQueryManager();
$webspaceManager = $this->container->get('sulu_core.webspace.webspace_manager');
$propertyEncoder = $this->container->get('sulu_document_manager.property_encoder');
$webspaces = $webspaceManager->getWebspaceCollection();
foreach ($webspaces as $webspace) {
foreach ($webspace->getAllLocalizations() as $localization) {
$locale = $localization->getLocalization();
$sql = <<<EOT
SELECT * FROM [nt:unstructured] WHERE %s = 2
EOT;
$query = $queryManager->createQuery(sprintf($sql, '[' . $propertyEncoder->localizedSystemName('nodeType', $locale) . ']'), 'JCR-SQL2');
$rows = $query->execute();
foreach ($rows as $row) {
$node = $row->getNode();
$internalLinkName = $propertyEncoder->localizedSystemName('internal_link', $locale);
try {
if (true === $directionUp) {
$internalUuid = $node->getPropertyValue($internalLinkName);
$internalNode = $session->getNodeByIdentifier($internalUuid);
$node->setProperty($internalLinkName, null);
$node->setProperty($internalLinkName, $internalNode);
} else {
$internalNode = $node->getPropertyValue($internalLinkName);
$internalNodeUuid = $internalNode->getIdentifier();
$node->setProperty($internalLinkName, null);
$node->setProperty($internalLinkName, $internalNodeUuid);
}
} catch (\Exception $e) {
echo $e->getMessage() . PHP_EOL;
}
}
}
}
}
示例9: getNodeByIdentifier
/**
* @see \PHPCR\SessionInterface::getNodeByIdentifier
*/
public function getNodeByIdentifier($id)
{
$node = $this->session->getNodeByIdentifier($id);
return new Node($node);
}