mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-28 01:30:15 +00:00
3af6a04c69
As far as I can tell, EchoIteratorDecorator is functionally identical to IteratorDecorator from includes/libs/iterators/ in core, so why have a separate copy? (EchoIteratorDecorator does pass through the return value of next() or rewind(), if any, but there shouldn't be any per the Iterator interface.) Change-Id: Ic763ec19c15f67d9c9b42ebffb88c52b9056ed22
19 lines
419 B
PHP
19 lines
419 B
PHP
<?php
|
|
|
|
/**
|
|
* Applies a callback to all values returned from the iterator
|
|
*/
|
|
class EchoCallbackIterator extends IteratorDecorator {
|
|
/** @var callable */
|
|
protected $callable;
|
|
|
|
public function __construct( Iterator $iterator, $callable ) {
|
|
parent::__construct( $iterator );
|
|
$this->callable = $callable;
|
|
}
|
|
|
|
public function current() {
|
|
return call_user_func( $this->callable, $this->iterator->current() );
|
|
}
|
|
}
|