1<?php 2 3// Protocol Buffers - Google's data interchange format 4// Copyright 2008 Google Inc. All rights reserved. 5// 6// Use of this source code is governed by a BSD-style 7// license that can be found in the LICENSE file or at 8// https://developers.google.com/open-source/licenses/bsd 9 10/** 11 * RepeatedField and RepeatedFieldIter are used by generated protocol message 12 * classes to manipulate repeated fields. 13 */ 14 15namespace Google\Protobuf\Internal; 16 17/** 18 * RepeatedFieldIter is used to iterate RepeatedField. It is also need for the 19 * foreach syntax. 20 */ 21class RepeatedFieldIter implements \Iterator 22{ 23 24 /** 25 * @ignore 26 */ 27 private $position; 28 /** 29 * @ignore 30 */ 31 private $container; 32 33 /** 34 * Create iterator instance for RepeatedField. 35 * 36 * @param array $container 37 * @ignore 38 */ 39 public function __construct($container) 40 { 41 $this->position = 0; 42 $this->container = $container; 43 } 44 45 /** 46 * Reset the status of the iterator 47 * 48 * @return void 49 * @todo need to add return type void (require update php version to 7.1) 50 */ 51 #[\ReturnTypeWillChange] 52 public function rewind() 53 { 54 $this->position = 0; 55 } 56 57 /** 58 * Return the element at the current position. 59 * 60 * @return object The element at the current position. 61 * @todo need to add return type mixed (require update php version to 8.0) 62 */ 63 #[\ReturnTypeWillChange] 64 public function current() 65 { 66 return $this->container[$this->position]; 67 } 68 69 /** 70 * Return the current position. 71 * 72 * @return integer The current position. 73 * @todo need to add return type mixed (require update php version to 8.0) 74 */ 75 #[\ReturnTypeWillChange] 76 public function key() 77 { 78 return $this->position; 79 } 80 81 /** 82 * Move to the next position. 83 * 84 * @return void 85 * @todo need to add return type void (require update php version to 7.1) 86 */ 87 #[\ReturnTypeWillChange] 88 public function next() 89 { 90 ++$this->position; 91 } 92 93 /** 94 * Check whether there are more elements to iterate. 95 * 96 * @return bool True if there are more elements to iterate. 97 */ 98 public function valid(): bool 99 { 100 return isset($this->container[$this->position]); 101 } 102} 103