diff options
Diffstat (limited to 'ext/spl/examples/limititerator.inc')
-rwxr-xr-x | ext/spl/examples/limititerator.inc | 72 |
1 files changed, 0 insertions, 72 deletions
diff --git a/ext/spl/examples/limititerator.inc b/ext/spl/examples/limititerator.inc deleted file mode 100755 index e471f5d0e4..0000000000 --- a/ext/spl/examples/limititerator.inc +++ /dev/null @@ -1,72 +0,0 @@ -<?php - -class LimitIterator implements Iterator -{ - protected $it; - protected $offset; - protected $count; - private $pos; - - // count === NULL means all - function __construct(Iterator $it, $offset = 0, $count = -1) - { - if ($offset < 0) { - throw new exception('Parameter offset must be > 0'); - } - if ($count < 0 && $count != -1) { - throw new exception('Parameter count must either be -1 or a value greater than or equal to 0'); - } - $this->it = $it; - $this->offset = $offset; - $this->count = $count; - $this->pos = 0; - } - - function seek($position) { - if ($position < $this->offset) { - throw new exception('Cannot seek to '.$position.' which is below offset '.$this->offset); - } - if ($position > $this->offset + $this->count && $this->count != -1) { - throw new exception('Cannot seek to '.$position.' which is behind offset '.$this->offset.' plus count '.$this->count); - } - if ($this->it instanceof SeekableIterator) { - $this->it->seek($position); - $this->pos = $position; - } else { - while($this->pos < $position && $this->it->hasMore()) { - $this->next(); - } - } - } - - function rewind() - { - $this->it->rewind(); - $this->pos = 0; - $this->seek($this->offset); - } - - function hasMore() { - return ($this->count == -1 || $this->pos < $this->offset + $this->count) - && $this->it->hasMore(); - } - - function key() { - return $this->it->key(); - } - - function current() { - return $this->it->current(); - } - - function next() { - $this->it->next(); - $this->pos++; - } - - function getPosition() { - return $this->pos; - } -} - -?>
\ No newline at end of file |