From c1f9b1f7b1b77776192048005dcc66dcf3df2bfb Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sat, 27 Dec 2014 15:41:37 +0100 Subject: Update to MediaWiki 1.24.1 --- includes/libs/MappedIterator.php | 117 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 includes/libs/MappedIterator.php (limited to 'includes/libs/MappedIterator.php') diff --git a/includes/libs/MappedIterator.php b/includes/libs/MappedIterator.php new file mode 100644 index 00000000..7fdde8a8 --- /dev/null +++ b/includes/libs/MappedIterator.php @@ -0,0 +1,117 @@ +vCallback = $vCallback; + $this->aCallback = isset( $options['accept'] ) ? $options['accept'] : null; + } + + public function next() { + $this->cache = array(); + parent::next(); + } + + public function rewind() { + $this->rewound = true; + $this->cache = array(); + parent::rewind(); + } + + public function accept() { + $value = call_user_func( $this->vCallback, $this->getInnerIterator()->current() ); + $ok = ( $this->aCallback ) ? call_user_func( $this->aCallback, $value ) : true; + if ( $ok ) { + $this->cache['current'] = $value; + } + + return $ok; + } + + public function key() { + $this->init(); + + return parent::key(); + } + + public function valid() { + $this->init(); + + return parent::valid(); + } + + public function current() { + $this->init(); + if ( parent::valid() ) { + return $this->cache['current']; + } else { + return null; // out of range + } + } + + /** + * Obviate the usual need for rewind() before using a FilterIterator in a manual loop + */ + protected function init() { + if ( !$this->rewound ) { + $this->rewind(); + } + } +} -- cgit v1.2.3-54-g00ecf