Created
December 11, 2012 20:49
-
-
Save hakre/4262006 to your computer and use it in GitHub Desktop.
NoRewindLimitIterator
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
<?php | |
class NoRewindLimitIterator extends IteratorIterator | |
{ | |
private $start, $count, $next; | |
public function __construct($it, $start, $count) { | |
parent::__construct($it); | |
$this->start = max(0, $start); | |
$this->count = max(0, $count); | |
} | |
public function rewind() { | |
$start = $this->start; | |
while($start--) { | |
parent::next(); | |
} | |
$this->next = 0; | |
} | |
public function next() { | |
parent::next(); | |
$this->next++; | |
} | |
public function valid() { | |
if (!parent::valid()) return false; | |
return $this->next < $this->count; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment