Debian Codegraph @

php/src/Google/Protobuf/Internal/RepeatedFieldIter.php

raw
1 <?php
2
3 // Protocol Buffers - Google's data interchange format
4 // Copyright 2008 Google Inc. All rights reserved.
5 // https://developers.google.com/protocol-buffers/
6 //
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions are
9 // met:
10 //
11 // * Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 // * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following disclaimer
15 // in the documentation and/or other materials provided with the
16 // distribution.
17 // * Neither the name of Google Inc. nor the names of its
18 // contributors may be used to endorse or promote products derived from
19 // this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
33 /**
34 * RepeatedField and RepeatedFieldIter are used by generated protocol message
35 * classes to manipulate repeated fields.
36 */
37
38 namespace Google\Protobuf\Internal;
39
40 /**
41 * RepeatedFieldIter is used to iterate RepeatedField. It is also need for the
42 * foreach syntax.
43 */
44 class RepeatedFieldIter implements \Iterator
45 {
46
47 /**
48 * @ignore
49 */
50 private $position;
51 /**
52 * @ignore
53 */
54 private $container;
55
56 /**
57 * Create iterator instance for RepeatedField.
58 *
59 * @param RepeatedField The RepeatedField instance for which this iterator
60 * is created.
61 * @ignore
62 */
63 public function __construct($container)
64 {
65 $this->position = 0;
66 $this->container = $container;
67 }
68
69 /**
70 * Reset the status of the iterator
71 *
72 * @return void
73 * @todo need to add return type void (require update php version to 7.1)
74 */
75 #[\ReturnTypeWillChange]
76 public function rewind()
77 {
78 $this->position = 0;
79 }
80
81 /**
82 * Return the element at the current position.
83 *
84 * @return object The element at the current position.
85 * @todo need to add return type mixed (require update php version to 8.0)
86 */
87 #[\ReturnTypeWillChange]
88 public function current()
89 {
90 return $this->container[$this->position];
91 }
92
93 /**
94 * Return the current position.
95 *
96 * @return integer The current position.
97 * @todo need to add return type mixed (require update php version to 8.0)
98 */
99 #[\ReturnTypeWillChange]
100 public function key()
101 {
102 return $this->position;
103 }
104
105 /**
106 * Move to the next position.
107 *
108 * @return void
109 * @todo need to add return type void (require update php version to 7.1)
110 */
111 #[\ReturnTypeWillChange]
112 public function next()
113 {
114 ++$this->position;
115 }
116
117 /**
118 * Check whether there are more elements to iterate.
119 *
120 * @return bool True if there are more elements to iterate.
121 */
122 public function valid(): bool
123 {
124 return isset($this->container[$this->position]);
125 }
126 }