container = $container; $this->key_type = $key_type; } /** * Reset the status of the iterator * * @return void */ public function rewind() { return reset($this->container); } /** * Return the element at the current position. * * @return object The element at the current position. */ public function current() { return current($this->container); } /** * Return the current key. * * @return object The current key. */ public function key() { $key = key($this->container); if ($this->key_type === GPBType::BOOL) { // PHP associative array stores bool as integer for key. return boolval($key); } elseif ($this->key_type === GPBType::STRING) { // PHP associative array stores int string as int for key. return strval($key); } else { return $key; } } /** * Move to the next position. * * @return void */ public function next() { return next($this->container); } /** * Check whether there are more elements to iterate. * * @return bool True if there are more elements to iterate. */ public function valid() { return key($this->container) !== null; } }