Skip to content

Commit 10f01c8

Browse files
committed
Add quick improvements and notes on SplitIterator
Just the stuff that was done really quickly (already done last week), and a note what we're missing for a clean solution, as there's absolutely no time to write the LimitCallbackIterator, that we'd actually want to have here.
1 parent e09d74e commit 10f01c8

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

SplitIterator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ private function splitOff() {
182182

183183
if(parent::valid()) {
184184
$this->currentSplitIterator
185-
= new SplitInnerIterator($this->getInnerIterator(), $this);
185+
= new SplitInnerIterator($this->getInnerIterator(), array($this, 'needsSplit'));
186186
return TRUE;
187187
} else {
188188
return FALSE;

SplitIterator/SplitInnerIterator.php

+18-4
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,27 @@
1414
* @subpackage Iterators
1515
*
1616
* @see SplitIterator
17+
*
18+
* @todo Instead of having a specific SplitInnerIterator, this could
19+
* actually be something like a {@see LimitCallbackIterator}, a
20+
* form of an {@see LimitIterator} that determines its starting
21+
* and stopping item not from a fixed index position, but from
22+
* a respective callback. For this iterator here we just need
23+
* the stop callback (always starting from the current position,
24+
* ignoring the start callback), and need to add the no-rewind
25+
* feature (as we wouldn't inherit from {@see NoRewindIterator}
26+
* anymore). Don't have the time to implement the full-fledged
27+
* limiting callback iterator right now, so we have just a
28+
* beginning (what's actually needed) here in the inner iterator
29+
* for the {@see SplitIterator} right now.
1730
*/
1831
class SplitInnerIterator extends NoRewindIterator {
19-
private $outerIterator;
32+
private $stopCallback;
2033

2134
private $valid = TRUE;
2235

23-
final public function __construct(Traversable $iterator, SplitIterator $outerIterator) {
24-
$this->outerIterator = $outerIterator;
36+
final public function __construct(Traversable $iterator, callable $stopCallback) {
37+
$this->stopCallback = $stopCallback;
2538
parent::__construct($iterator);
2639
}
2740

@@ -37,7 +50,8 @@ final public function next() {
3750
if(!$this->valid)
3851
return;
3952

40-
if($this->outerIterator->needsSplit($this->key(), $this->current())) {
53+
$stopCallback = $this->stopCallback; // Due to PHP's syntax restrictions
54+
if($stopCallback($this->key(), $this->current())) {
4155
$this->valid = FALSE;
4256
return;
4357
}

0 commit comments

Comments
 (0)