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

/lib/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]) && is_array($this->modelData[$this->collection_key])) { 
  6. reset($this->modelData[$this->collection_key]); 
  7.  
  8. public function current() 
  9. $this->coerceType($this->key()); 
  10. if (is_array($this->modelData[$this->collection_key])) { 
  11. return current($this->modelData[$this->collection_key]); 
  12.  
  13. public function key() 
  14. if (isset($this->modelData[$this->collection_key]) && is_array($this->modelData[$this->collection_key])) { 
  15. return key($this->modelData[$this->collection_key]); 
  16.  
  17. public function next() 
  18. return next($this->modelData[$this->collection_key]); 
  19.  
  20. public function valid() 
  21. $key = $this->key(); 
  22. return $key !== null && $key !== false; 
  23.  
  24. public function count() 
  25. return count($this->modelData[$this->collection_key]); 
  26.  
  27. public function offsetExists ($offset) 
  28. if (!is_numeric($offset)) { 
  29. return parent::offsetExists($offset); 
  30. return isset($this->modelData[$this->collection_key][$offset]); 
  31.  
  32. public function offsetGet($offset) 
  33. if (!is_numeric($offset)) { 
  34. return parent::offsetGet($offset); 
  35. $this->coerceType($offset); 
  36. return $this->modelData[$this->collection_key][$offset]; 
  37.  
  38. public function offsetSet($offset, $value) 
  39. if (!is_numeric($offset)) { 
  40. return parent::offsetSet($offset, $value); 
  41. $this->modelData[$this->collection_key][$offset] = $value; 
  42.  
  43. public function offsetUnset($offset) 
  44. if (!is_numeric($offset)) { 
  45. return parent::offsetUnset($offset); 
  46. unset($this->modelData[$this->collection_key][$offset]); 
  47.  
  48. private function coerceType($offset) 
  49. $typeKey = $this->keyType($this->collection_key); 
  50. if (isset($this->$typeKey) && !is_object($this->modelData[$this->collection_key][$offset])) { 
  51. $type = $this->$typeKey; 
  52. $this->modelData[$this->collection_key][$offset] = 
  53. new $type($this->modelData[$this->collection_key][$offset]);