Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.
<?php

if (!class_exists('Google_Client')) {
  require_once dirname(__FILE__) . '/autoload.php';
}

/**
 * Extension to the regular Google_Model that automatically
 * exposes the items array for iteration, so you can just
 * iterate over the object rather than a reference inside.
 */
class Google_Collection extends Google_Model implements Iterator, Countable
{
  protected $collection_key = 'items';

< public function rewind()
> public function rewind(): void
{ if (isset($this->modelData[$this->collection_key]) && is_array($this->modelData[$this->collection_key])) { reset($this->modelData[$this->collection_key]); } }
> #[\ReturnTypeWillChange]
public function current() { $this->coerceType($this->key()); if (is_array($this->modelData[$this->collection_key])) { return current($this->modelData[$this->collection_key]); }
> return null;
}
> #[\ReturnTypeWillChange]
public function key() { if (isset($this->modelData[$this->collection_key]) && is_array($this->modelData[$this->collection_key])) { return key($this->modelData[$this->collection_key]); }
> return null;
}
< public function next()
> public function next(): void
{
< return next($this->modelData[$this->collection_key]);
> next($this->modelData[$this->collection_key]);
}
< public function valid()
> public function valid(): bool
{ $key = $this->key(); return $key !== null && $key !== false; }
< public function count()
> public function count(): int
{ if (!isset($this->modelData[$this->collection_key])) { return 0; } return count($this->modelData[$this->collection_key]); }
< public function offsetExists($offset)
> public function offsetExists($offset): bool
{ if (!is_numeric($offset)) { return parent::offsetExists($offset); } return isset($this->modelData[$this->collection_key][$offset]); }
> #[\ReturnTypeWillChange]
public function offsetGet($offset) { if (!is_numeric($offset)) { return parent::offsetGet($offset); } $this->coerceType($offset); return $this->modelData[$this->collection_key][$offset]; }
< public function offsetSet($offset, $value)
> public function offsetSet($offset, $value): void
{ if (!is_numeric($offset)) {
< return parent::offsetSet($offset, $value);
> parent::offsetSet($offset, $value); > return;
} $this->modelData[$this->collection_key][$offset] = $value; }
< public function offsetUnset($offset)
> public function offsetUnset($offset): void
{ if (!is_numeric($offset)) {
< return parent::offsetUnset($offset);
> parent::offsetUnset($offset); > return;
} unset($this->modelData[$this->collection_key][$offset]); } private function coerceType($offset) { $typeKey = $this->keyType($this->collection_key); if (isset($this->$typeKey) && !is_object($this->modelData[$this->collection_key][$offset])) { $type = $this->$typeKey; $this->modelData[$this->collection_key][$offset] = new $type($this->modelData[$this->collection_key][$offset]); } } }