-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJackalopeLoader.php
46 lines (39 loc) · 1.05 KB
/
JackalopeLoader.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
namespace Symfony\Bundle\DoctrinePHPCRBundle;
class JackalopeLoader
{
protected $container;
protected $session;
protected $config;
public function __construct($container, $config)
{
$this->container = $container;
$this->config = $config;
}
public function getSession()
{
if (!$this->session) {
$this->session = $this->container->get('jackalope.session');
}
return $this->session;
}
/**
* Setup the base structure for this importer if necessary.
*
* @return \PHPCR\NodeInterface
* @throws todo.. findout which exceptions might be thrown.
*/
public function initPath($path)
{
$node = $this->getSession()->getRootNode();
$nodes = explode('/', trim($path, '/'));
foreach ($nodes as $subpath) {
if ($node->hasNode($subpath)) {
$node = $node->getNode($subpath);
} else {
$node = $node->addNode($subpath);
}
}
return $node;
}
}