Skip to content

Commit

Permalink
Fixed node path iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
dantleech committed Jul 4, 2013
1 parent 182b2e8 commit 5f4ef20
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions src/Jackalope/NodePathIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class NodePathIterator implements \SeekableIterator, \ArrayAccess
protected $paths;
protected $typeFilter;
protected $class;
protected $fullyLoaded = false;

protected $batchSize;

Expand Down Expand Up @@ -99,6 +100,10 @@ protected function loadBatch()
$this->batchSize
);

if (!isset($this->paths[$this->position + 1])) {
$this->fullyLoaded = true;
}

$nodes = $this->objectManager->getNodesByPathAsArray(
$paths, $this->class, $this->typeFilter
);
Expand All @@ -108,22 +113,25 @@ protected function loadBatch()
}
}

protected function loadSingle($path)
protected function loadAll()
{
$paths = array($path);
$nodes = $this->objectManager->getNodesByPath($paths, $this->class, $this->typeFilter);
$node = current($nodes);
$this->nodes[$path] = $node ? $node : null;
if (!$this->fullyLoaded) {
foreach ($this as $node) {
// we could probably do this slightly more efficiently but
// this does not add much overhead.
}
$this->fullyLoaded = true;
}
}

protected function ensurePathLoaded($path)
public function ensurePathLoaded($offset)
{
if (in_array($path, $this->paths)) {
if (!array_key_exists($path, $this->nodes)) {
$this->loadSingle($path);
}
} else {
$this->nodes[$path] = null;
if (!isset($this->nodes[$offset])) {
$this->loadAll();
}

if (!isset($this->nodes[$offset])) {
$this->nodes[$offset] = null;
}
}

Expand Down

0 comments on commit 5f4ef20

Please sign in to comment.