+// Wrapper class to build a SPL iterator from a PlIterator
+class SPLIterator implements Iterator
+{
+ private $it;
+ private $pos;
+ private $value;
+
+ public function __construct(PlIterator $it)
+ {
+ $this->it = $it;
+ $this->pos = 0;
+ $this->value = $this->it->next();
+ }
+
+ public function rewind()
+ {
+ if ($this->pos != 0) {
+ throw new Exception("Rewind not supported on this iterator");
+ }
+ }
+
+ public function current()
+ {
+ return $this->value;
+ }
+
+ public function key()
+ {
+ return $this->pos;
+ }
+
+ public function next()
+ {
+ ++$this->pos;
+ $this->value = $this->it->next();
+ }
+
+ public function valid()
+ {
+ return !!$this->value;
+ }
+}
+