See Release Notes
Long Term Support Release
Differences Between: [Versions 311 and 401] [Versions 400 and 401]
1 <?php 2 /* 3 * Copyright 2017-present MongoDB, Inc. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * https://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 namespace MongoDB\Model; 19 20 use Closure; 21 use Iterator; 22 use IteratorIterator; 23 use ReturnTypeWillChange; 24 use Traversable; 25 26 /** 27 * Iterator to apply a callback before returning an element 28 * 29 * @internal 30 */ 31 class CallbackIterator implements Iterator 32 { 33 /** @var Closure */ 34 private $callback; 35 36 /** @var Iterator */ 37 private $iterator; 38 39 public function __construct(Traversable $traversable, Closure $callback) 40 { 41 $this->iterator = $traversable instanceof Iterator ? $traversable : new IteratorIterator($traversable); 42 $this->callback = $callback; 43 } 44 45 /** 46 * @see https://php.net/iterator.current 47 * @return mixed 48 */ 49 #[ReturnTypeWillChange] 50 public function current() 51 { 52 return ($this->callback)($this->iterator->current()); 53 } 54 55 /** 56 * @see https://php.net/iterator.key 57 * @return mixed 58 */ 59 #[ReturnTypeWillChange] 60 public function key() 61 { 62 return $this->iterator->key(); 63 } 64 65 /** 66 * @see https://php.net/iterator.next 67 */ 68 public function next(): void 69 { 70 $this->iterator->next(); 71 } 72 73 /** 74 * @see https://php.net/iterator.rewind 75 */ 76 public function rewind(): void 77 { 78 $this->iterator->rewind(); 79 } 80 81 /** 82 * @see https://php.net/iterator.valid 83 */ 84 public function valid(): bool 85 { 86 return $this->iterator->valid(); 87 } 88 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body