media-cloud-sync
/
includes
/
sdk
/
google
/
google
/
protobuf
/
src
/
Google
/
Protobuf
/
Internal
/
MapFieldIter.php
MapFieldIter.php in Media Cloud Sync 1.4.2, at includes/sdk/google/google/protobuf/src/Google/Protobuf/Internal/MapFieldIter.php
| 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 | * MapField and MapFieldIter are used by generated protocol message classes to |
| 11 | * manipulate map fields. |
| 12 | */ |
| 13 | namespace Dudlewebs\WPMCS\GCP\Google\Protobuf\Internal; |
| 14 | |
| 15 | /** |
| 16 | * MapFieldIter is used to iterate MapField. It is also need for the foreach |
| 17 | * syntax. |
| 18 | */ |
| 19 | class MapFieldIter implements \Iterator |
| 20 | { |
| 21 | /** |
| 22 | * @ignore |
| 23 | */ |
| 24 | private $container; |
| 25 | /** |
| 26 | * @ignore |
| 27 | */ |
| 28 | private $key_type; |
| 29 | /** |
| 30 | * Create iterator instance for MapField. |
| 31 | * |
| 32 | * @param array $container |
| 33 | * @param GPBType $key_type Map key type. |
| 34 | * @ignore |
| 35 | */ |
| 36 | public function __construct($container, $key_type) |
| 37 | { |
| 38 | $this->container = $container; |
| 39 | $this->key_type = $key_type; |
| 40 | } |
| 41 | /** |
| 42 | * Reset the status of the iterator |
| 43 | * |
| 44 | * @return void |
| 45 | * @todo need to add return type void (require update php version to 7.1) |
| 46 | */ |
| 47 | #[\ReturnTypeWillChange] |
| 48 | public function rewind() |
| 49 | { |
| 50 | \reset($this->container); |
| 51 | } |
| 52 | /** |
| 53 | * Return the element at the current position. |
| 54 | * |
| 55 | * @return object The element at the current position. |
| 56 | * @todo need to add return type mixed (require update php version to 8.0) |
| 57 | */ |
| 58 | #[\ReturnTypeWillChange] |
| 59 | public function current() |
| 60 | { |
| 61 | return \current($this->container); |
| 62 | } |
| 63 | /** |
| 64 | * Return the current key. |
| 65 | * |
| 66 | * @return object The current key. |
| 67 | * @todo need to add return type mixed (require update php version to 8.0) |
| 68 | */ |
| 69 | #[\ReturnTypeWillChange] |
| 70 | public function key() |
| 71 | { |
| 72 | $key = \key($this->container); |
| 73 | switch ($this->key_type) { |
| 74 | case GPBType::INT64: |
| 75 | case GPBType::UINT64: |
| 76 | case GPBType::FIXED64: |
| 77 | case GPBType::SFIXED64: |
| 78 | case GPBType::SINT64: |
| 79 | if (\PHP_INT_SIZE === 8) { |
| 80 | return $key; |
| 81 | } |
| 82 | // Intentionally fall through |
| 83 | case GPBType::STRING: |
| 84 | // PHP associative array stores int string as int for key. |
| 85 | return \strval($key); |
| 86 | case GPBType::BOOL: |
| 87 | // PHP associative array stores bool as integer for key. |
| 88 | return \boolval($key); |
| 89 | default: |
| 90 | return $key; |
| 91 | } |
| 92 | } |
| 93 | /** |
| 94 | * Move to the next position. |
| 95 | * |
| 96 | * @return void |
| 97 | * @todo need to add return type void (require update php version to 7.1) |
| 98 | */ |
| 99 | #[\ReturnTypeWillChange] |
| 100 | public function next() |
| 101 | { |
| 102 | \next($this->container); |
| 103 | } |
| 104 | /** |
| 105 | * Check whether there are more elements to iterate. |
| 106 | * |
| 107 | * @return bool True if there are more elements to iterate. |
| 108 | */ |
| 109 | public function valid() : bool |
| 110 | { |
| 111 | return \key($this->container) !== null; |
| 112 | } |
| 113 | } |
| 114 |