-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:jackalope/jackalope
- Loading branch information
Showing
13 changed files
with
201 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
/** | ||
* Allows easy iteration through a list of Nodes with nextNode as well as a skip method | ||
* inherited from RangeIterator. | ||
*/ | ||
class jackalope_NodeIterator extends jackalope_RangeIterator implements PHPCR_NodeIteratorInterface { | ||
/** | ||
* Returns the next Node in the iteration. | ||
* | ||
* @return PHPCR_NodeInterface | ||
* @throws OutOfBoundsException if the iterator contains no more elements. | ||
*/ | ||
public function nextNode() { | ||
return $this->next(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
/** | ||
* Allows easy iteration through a list of Properties with nextProperty as well as a skip method | ||
* inherited from RangeIterator. | ||
*/ | ||
class jackalope_PropertyIterator extends jackalope_RangeIterator implements PHPCR_PropertyIteratorInterface { | ||
/** | ||
* Returns the next Property in the iteration. | ||
* | ||
* @return PHPCR_PropertyInterface | ||
* @throws OutOfBoundsException if the iterator contains no more elements. | ||
*/ | ||
public function nextProperty() { | ||
return $this->next(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
/** | ||
* Extends Iterator with the skip, getSize and getPosition methods. The base | ||
* iterator of all type-specific iterators in the JCR and its sub packages. | ||
*/ | ||
class jackalope_RangeIterator implements PHPCR_RangeIteratorInterface { | ||
protected $items; | ||
protected $pos; | ||
public function __construct($items) { | ||
$this->items = $items; | ||
$this->pos = 0; | ||
} | ||
|
||
/** | ||
* Skip a number of elements in the iterator. | ||
* | ||
* @param integer $skipNum the non-negative number of elements to skip | ||
* @throws OutOfBoundsException if skipped past the last element in the iterator. | ||
*/ | ||
public function skip($skipNum) { | ||
if ($this->pos + $skipNum >= $this->getSize()) { | ||
throw new OutOfBoundsException('skipping past end'); | ||
} | ||
$this->pos += $skipNum; | ||
} | ||
|
||
/** | ||
* Returns the total number of of items available through this iterator. | ||
* | ||
* For example, for some node $n, $n->getNodes()->getSize() returns the | ||
* number of child nodes of $n visible through the current Session. | ||
* | ||
* In some implementations precise information about the number of elements may | ||
* not be available. In such cases this method must return -1. API clients will | ||
* then be able to use RangeIterator->getNumberRemaining() to get an | ||
* estimate on the number of elements. | ||
* | ||
* @return integer | ||
*/ | ||
public function getSize() { | ||
return size($this->items); | ||
} | ||
|
||
/** | ||
* Returns the current position within the iterator. The number | ||
* returned is the 0-based index of the next element in the iterator, | ||
* i.e. the one that will be returned on the subsequent next() call. | ||
* | ||
* Note that this method does not check if there is a next element, | ||
* i.e. an empty iterator will always return 0. | ||
* | ||
* @return integer | ||
*/ | ||
public function getPosition() { | ||
return $this->pos; | ||
} | ||
|
||
/** php has no strong typing, so we can just do this here */ | ||
protected function next() { | ||
if ($this->pos >= $this->getSize()) { | ||
throw new OutOfBoundsException('skipping past end'); | ||
} | ||
return $this->items[$this->pos++]; | ||
} | ||
} |
Oops, something went wrong.