From: Aaron Schulz Date: Tue, 31 Dec 2013 23:33:15 +0000 (-0800) Subject: Moved MappedIterator to /libs and changed exception type X-Git-Tag: 1.31.0-rc.0~17347^2 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/membres/message.php?a=commitdiff_plain;h=deec3478c749badd21037ec3607478c846ff03b6;p=lhc%2Fweb%2Fwiklou.git Moved MappedIterator to /libs and changed exception type Now throws UnexpectedValueException rather than MWException. Change-Id: Id466b66f43db97c5837030d166b9abd66fd56e0d --- diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index 034aa154b8..09cbe827d3 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -681,6 +681,7 @@ $wgAutoloadLocalClasses = array( 'HttpStatus' => 'includes/libs/HttpStatus.php', 'IEContentAnalyzer' => 'includes/libs/IEContentAnalyzer.php', 'IEUrlExtension' => 'includes/libs/IEUrlExtension.php', + 'MappedIterator' => 'includes/libs/MappedIterator.php', 'JavaScriptMinifier' => 'includes/libs/JavaScriptMinifier.php', 'JSCompilerContext' => 'includes/libs/jsminplus.php', 'JSMinPlus' => 'includes/libs/jsminplus.php', @@ -1075,7 +1076,6 @@ $wgAutoloadLocalClasses = array( 'IP' => 'includes/utils/IP.php', 'MWCryptRand' => 'includes/utils/MWCryptRand.php', 'MWFunction' => 'includes/utils/MWFunction.php', - 'MappedIterator' => 'includes/utils/MappedIterator.php', 'RegexlikeReplacer' => 'includes/utils/StringUtils.php', 'ReplacementArray' => 'includes/utils/StringUtils.php', 'Replacer' => 'includes/utils/StringUtils.php', diff --git a/includes/libs/MappedIterator.php b/includes/libs/MappedIterator.php new file mode 100644 index 0000000000..7fdde8a81a --- /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(); + } + } +} diff --git a/includes/utils/MappedIterator.php b/includes/utils/MappedIterator.php deleted file mode 100644 index f2e6df6be9..0000000000 --- a/includes/utils/MappedIterator.php +++ /dev/null @@ -1,117 +0,0 @@ -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(); - } - } -}