本文整理汇总了PHP中PHPCR\SessionInterface::getRootNode方法的典型用法代码示例。如果您正苦于以下问题:PHP SessionInterface::getRootNode方法的具体用法?PHP SessionInterface::getRootNode怎么用?PHP SessionInterface::getRootNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPCR\SessionInterface
的用法示例。
在下文中一共展示了SessionInterface::getRootNode方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testPostTree
public function testPostTree()
{
$data1 = ['title' => 'news', 'tags' => ['tag1', 'tag2'], 'url' => '/news', 'article' => 'Test'];
$data2 = ['title' => 'test-1', 'tags' => ['tag1', 'tag2'], 'url' => '/news/test', 'article' => 'Test'];
$client = $this->createAuthenticatedClient();
$client->request('POST', '/api/nodes?template=default&webspace=sulu_io&language=en', $data1);
$this->assertEquals(200, $client->getResponse()->getStatusCode());
$response = json_decode($client->getResponse()->getContent());
$uuid = $response->id;
$client->request('POST', '/api/nodes?template=default&parent=' . $uuid . '&webspace=sulu_io&language=en', $data2);
$this->assertEquals(200, $client->getResponse()->getStatusCode());
$response = json_decode($client->getResponse()->getContent());
$this->assertEquals('test-1', $response->title);
$this->assertEquals('Test', $response->article);
$this->assertEquals('/news/test', $response->url);
$this->assertEquals(['tag1', 'tag2'], $response->tags);
$this->assertEquals($this->getTestUserId(), $response->creator);
$this->assertEquals($this->getTestUserId(), $response->changer);
$root = $this->session->getRootNode();
$route = $root->getNode('cmf/sulu_io/routes/en/news/test');
/** @var NodeInterface $content */
$content = $route->getPropertyValue('sulu:content');
$this->assertEquals('test-1', $content->getProperty('i18n:en-title')->getString());
$this->assertEquals('Test', $content->getProperty('i18n:en-article')->getString());
$this->assertCount(2, $content->getPropertyValue('i18n:en-tags'));
$this->assertEquals($this->getTestUserId(), $content->getPropertyValue('i18n:en-creator'));
$this->assertEquals($this->getTestUserId(), $content->getPropertyValue('i18n:en-changer'));
// check parent
$this->assertEquals($uuid, $content->getParent()->getIdentifier());
}
示例2: removeTestNode
protected function removeTestNode()
{
$root = $this->session->getRootNode();
if ($root->hasNode($this->testNodeName)) {
$root->getNode($this->testNodeName)->remove();
$this->session->save();
}
}
示例3: handleSession
private function handleSession(SessionInterface $session, $fileName)
{
if ($session->getRootNode()->hasNode('cmf')) {
$session->getNode('/cmf')->remove();
$session->save();
}
$session->importXML('/', $fileName, ImportUUIDBehaviorInterface::IMPORT_UUID_COLLISION_THROW);
$session->save();
}
示例4: initProperties
/**
* This method populates the test case properties both at test setUp
* and after renewing the session.
*
* The default schema is to have a root node /test_<something> with one
* child node per test with the node name being the test name.
*/
protected function initProperties()
{
$this->session = $this->sharedFixture['session'];
$this->node = null;
$this->rootNode = $this->session->getRootNode();
$children = $this->rootNode->getNodes('tests_*');
$child = $children->current();
if ($child && $child->hasNode($this->getName())) {
$this->node = $child->getNode($this->getName());
}
}
示例5: testOverride
public function testOverride()
{
$property = new Property('url', [], 'resource_locator');
$property->setValue('/test');
$node = $this->sessionManager->getContentNode('sulu_io')->addNode('test');
$node->addMixin('sulu:content');
$this->session->save();
$this->resourceLocator->write($node, $property, 1, 'sulu_io', 'en');
$this->assertEquals('/test', $node->getPropertyValue('url'));
$this->assertTrue($this->session->getRootNode()->hasNode('cmf/sulu_io/routes/en/test'));
$property->setValue('/test-2');
$this->resourceLocator->write($node, $property, 1, 'sulu_io', 'en');
$this->assertEquals('/test-2', $node->getPropertyValue('url'));
$this->assertTrue($this->session->getRootNode()->hasNode('cmf/sulu_io/routes/en/test-2'));
}
示例6: createPath
/**
* Create a path.
*
* @param string $path
*
* @return NodeInterface
*/
public function createPath($path)
{
$current = $this->session->getRootNode();
$segments = preg_split('#/#', $path, null, PREG_SPLIT_NO_EMPTY);
foreach ($segments as $segment) {
if ($current->hasNode($segment)) {
$current = $current->getNode($segment);
} else {
$current = $current->addNode($segment);
$current->addMixin('mix:referenceable');
$current->setProperty('jcr:uuid', UUIDHelper::generateUUID());
}
}
return $current;
}
示例7: purgeWorkspace
/**
* Delete all content in the workspace this session is bound to.
*
* Remember to save the session after calling the purge method.
*
* Note that if you want to delete a node under your root node, you can just
* use the remove method on that node. This method is just here to help you
* because the implementation might add nodes like jcr:system to the root
* node which you are not allowed to remove.
*
* @param SessionInterface $session the session to remove all children of
* the root node
*
* @see isSystemItem
*/
public static function purgeWorkspace(SessionInterface $session)
{
$root = $session->getRootNode();
/** @var $property PropertyInterface */
foreach ($root->getProperties() as $property) {
if (!self::isSystemItem($property)) {
$property->remove();
}
}
/** @var $node NodeInterface */
foreach ($root->getNodes() as $node) {
if (!self::isSystemItem($node)) {
$node->remove();
}
}
}
示例8: testPrimaryItem
public function testPrimaryItem()
{
$this->registerNodeTypePrimaryItem();
// Create a node of that type
$root = $this->session->getRootNode();
if ($root->hasNode('test_node')) {
$node = $root->getNode('test_node');
$node->remove();
$this->session->save();
}
$node = $root->addNode('test_node', 'phpcr:primary_item_test');
$node->setProperty('phpcr:content', 'test');
$this->session->save();
// Check the primary item of the new node
$primary = $node->getPrimaryItem();
$this->assertInstanceOf('PHPCR\\ItemInterface', $node);
$this->assertEquals('phpcr:content', $primary->getName());
}
示例9: createNodesWithUuid
/**
* Creates every node on the path to the given node. Also uses the same UUIDs for these nodes.
*
* @param NodeInterface $node
*/
private function createNodesWithUuid(NodeInterface $node)
{
$path = $node->getPath();
if ($this->liveSession->itemExists($path)) {
return;
}
$currentDefaultNode = $node->getSession()->getRootNode();
$currentLiveNode = $this->liveSession->getRootNode();
$pathSegments = explode('/', ltrim($path, '/'));
foreach ($pathSegments as $pathSegment) {
$currentDefaultNode = $currentDefaultNode->getNode($pathSegment);
if ($currentLiveNode->hasNode($pathSegment)) {
$currentLiveNode = $currentLiveNode->getNode($pathSegment);
continue;
}
$currentLiveNode = $currentLiveNode->addNode($pathSegment);
$currentLiveNode->setMixins(['mix:referenceable']);
$currentLiveNode->setProperty('jcr:uuid', $currentDefaultNode->getIdentifier());
}
}
示例10: migrateHome
private function migrateHome(SessionInterface $session, $from, $to, $referenceWebspace)
{
$webspaceManager = $this->container->get('sulu_core.webspace.webspace_manager');
$pathRegistry = $this->container->get('sulu_document_manager.path_segment_registry');
$webspaces = $webspaceManager->getWebspaceCollection();
foreach ($webspaces as $webspace) {
$webspacePath = sprintf('/%s/%s', $pathRegistry->getPathSegment('base'), $webspace->getKey());
$homeNodeName = $pathRegistry->getPathSegment('content');
$webspace = $session->getNode($webspacePath);
if ($referenceWebspace) {
$webspace->addMixin('mix:referenceable');
} else {
$webspace->removeMixin('mix:referenceable');
}
$homeNode = $webspace->getNode($homeNodeName);
$tmpNode = $session->getRootNode()->addNode('/tmp');
$tmpNode->addMixin('mix:referenceable');
$session->save();
$homeNodeReferences = $homeNode->getReferences();
$homeNodeReferenceValues = [];
foreach ($homeNodeReferences as $homeNodeReference) {
/* @var Property $homeNodeReference */
$homeNodeReferenceValues[$homeNodeReference->getPath()] = $homeNodeReference->getValue();
$homeNodeReference->setValue($tmpNode);
}
$session->save();
$homeNode->removeMixin($from);
$session->save();
$homeNode->addMixin($to);
$session->save();
foreach ($homeNodeReferences as $homeNodeReference) {
$homeNodeReference->setValue($homeNodeReferenceValues[$homeNodeReference->getPath()], PropertyType::REFERENCE);
}
$session->save();
$tmpNode->remove();
}
}
示例11: getRootNode
/**
* @see \PHPCR\SessionInterface::getRootNode
*/
public function getRootNode()
{
return new Node($this->session->getRootNode());
}
示例12: down
public function down(SessionInterface $session)
{
$session->getRootNode()->getNode('hello')->remove();
}
示例13: up
/**
* {@inheritdoc}
*/
public function up(SessionInterface $session)
{
$root = $session->getRootNode();
$this->upgradeNode($root);
}