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(); } } }