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).

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