Google_Collection

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.

Defined (1)

The class is defined in the following location(s).

/src/Google/Collection.php  
  1. class Google_Collection extends Google_Model implements Iterator, Countable 
  2. protected $collection_key = 'items'; 
  3.  
  4. public function rewind() 
  5. if (isset($this->modelData[$this->collection_key]) 
  6. && is_array($this->modelData[$this->collection_key])) { 
  7. reset($this->modelData[$this->collection_key]); 
  8.  
  9. public function current() 
  10. $this->coerceType($this->key()); 
  11. if (is_array($this->modelData[$this->collection_key])) { 
  12. return current($this->modelData[$this->collection_key]); 
  13.  
  14. public function key() 
  15. if (isset($this->modelData[$this->collection_key]) 
  16. && is_array($this->modelData[$this->collection_key])) { 
  17. return key($this->modelData[$this->collection_key]); 
  18.  
  19. public function next() 
  20. return next($this->modelData[$this->collection_key]); 
  21.  
  22. public function valid() 
  23. $key = $this->key(); 
  24. return $key !== null && $key !== false; 
  25.  
  26. public function count() 
  27. return count($this->modelData[$this->collection_key]); 
  28.  
  29. public function offsetExists ($offset) 
  30. if (!is_numeric($offset)) { 
  31. return parent::offsetExists($offset); 
  32. return isset($this->modelData[$this->collection_key][$offset]); 
  33.  
  34. public function offsetGet($offset) 
  35. if (!is_numeric($offset)) { 
  36. return parent::offsetGet($offset); 
  37. $this->coerceType($offset); 
  38. return $this->modelData[$this->collection_key][$offset]; 
  39.  
  40. public function offsetSet($offset, $value) 
  41. if (!is_numeric($offset)) { 
  42. return parent::offsetSet($offset, $value); 
  43. $this->modelData[$this->collection_key][$offset] = $value; 
  44.  
  45. public function offsetUnset($offset) 
  46. if (!is_numeric($offset)) { 
  47. return parent::offsetUnset($offset); 
  48. unset($this->modelData[$this->collection_key][$offset]); 
  49.  
  50. private function coerceType($offset) 
  51. $typeKey = $this->keyType($this->collection_key); 
  52. if (isset($this->$typeKey) && !is_object($this->modelData[$this->collection_key][$offset])) { 
  53. $type = $this->$typeKey; 
  54. $this->modelData[$this->collection_key][$offset] = 
  55. new $type($this->modelData[$this->collection_key][$offset]);