| 1 | <?php |
| 2 | /** |
| 3 | * Allows extending classes to decorate an Iterator with |
| 4 | * reduced boilerplate. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along |
| 17 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 19 | * http://www.gnu.org/copyleft/gpl.html |
| 20 | * |
| 21 | * @stable to extend |
| 22 | * @file |
| 23 | * @ingroup Maintenance |
| 24 | */ |
| 25 | abstract class IteratorDecorator implements Iterator { |
| 26 | protected Iterator $iterator; |
| 27 | |
| 28 | /** |
| 29 | * @stable to call |
| 30 | * |
| 31 | * @param Iterator $iterator |
| 32 | */ |
| 33 | public function __construct( Iterator $iterator ) { |
| 34 | $this->iterator = $iterator; |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * @inheritDoc |
| 39 | * @stable to override |
| 40 | */ |
| 41 | #[\ReturnTypeWillChange] |
| 42 | public function current() { |
| 43 | return $this->iterator->current(); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * @inheritDoc |
| 48 | * @stable to override |
| 49 | */ |
| 50 | #[\ReturnTypeWillChange] |
| 51 | public function key() { |
| 52 | return $this->iterator->key(); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * @inheritDoc |
| 57 | * @stable to override |
| 58 | */ |
| 59 | public function next(): void { |
| 60 | $this->iterator->next(); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * @inheritDoc |
| 65 | * @stable to override |
| 66 | */ |
| 67 | public function rewind(): void { |
| 68 | $this->iterator->rewind(); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * @inheritDoc |
| 73 | * @stable to override |
| 74 | */ |
| 75 | public function valid(): bool { |
| 76 | return $this->iterator->valid(); |
| 77 | } |
| 78 | } |