PluginProbe
Authorizer / 2.8.1
Authorizer v2.8.1
3.15.3 3.15.2 3.15.1 3.15.0 3.14.3 3.14.4 3.14.2 3.14.1 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.9.0 2.9.1 2.9.10 2.9.11 2.9.12 2.9.13 2.9.2 2.9.3 2.9.6 All 126 releases
authorizer / vendor / google-api-php-client / src / Google / Collection.php

Collection.php in Authorizer 2.8.1, at vendor/google-api-php-client/src/Google/Collection.php

102 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!class_exists('Google_Client')) {
4 require_once dirname(__FILE__) . '/autoload.php';
5 }
6
7 /**
8 * Extension to the regular Google_Model that automatically
9 * exposes the items array for iteration, so you can just
10 * iterate over the object rather than a reference inside.
11 */
12 class Google_Collection extends Google_Model implements Iterator, Countable
13 {
14 protected $collection_key = 'items';
15
16 public function rewind()
17 {
18 if (isset($this->modelData[$this->collection_key])
19 && is_array($this->modelData[$this->collection_key])) {
20 reset($this->modelData[$this->collection_key]);
21 }
22 }
23
24 public function current()
25 {
26 $this->coerceType($this->key());
27 if (is_array($this->modelData[$this->collection_key])) {
28 return current($this->modelData[$this->collection_key]);
29 }
30 }
31
32 public function key()
33 {
34 if (isset($this->modelData[$this->collection_key])
35 && is_array($this->modelData[$this->collection_key])) {
36 return key($this->modelData[$this->collection_key]);
37 }
38 }
39
40 public function next()
41 {
42 return next($this->modelData[$this->collection_key]);
43 }
44
45 public function valid()
46 {
47 $key = $this->key();
48 return $key !== null && $key !== false;
49 }
50
51 public function count()
52 {
53 if (!isset($this->modelData[$this->collection_key])) {
54 return 0;
55 }
56 return count($this->modelData[$this->collection_key]);
57 }
58
59 public function offsetExists($offset)
60 {
61 if (!is_numeric($offset)) {
62 return parent::offsetExists($offset);
63 }
64 return isset($this->modelData[$this->collection_key][$offset]);
65 }
66
67 public function offsetGet($offset)
68 {
69 if (!is_numeric($offset)) {
70 return parent::offsetGet($offset);
71 }
72 $this->coerceType($offset);
73 return $this->modelData[$this->collection_key][$offset];
74 }
75
76 public function offsetSet($offset, $value)
77 {
78 if (!is_numeric($offset)) {
79 return parent::offsetSet($offset, $value);
80 }
81 $this->modelData[$this->collection_key][$offset] = $value;
82 }
83
84 public function offsetUnset($offset)
85 {
86 if (!is_numeric($offset)) {
87 return parent::offsetUnset($offset);
88 }
89 unset($this->modelData[$this->collection_key][$offset]);
90 }
91
92 private function coerceType($offset)
93 {
94 $typeKey = $this->keyType($this->collection_key);
95 if (isset($this->$typeKey) && !is_object($this->modelData[$this->collection_key][$offset])) {
96 $type = $this->$typeKey;
97 $this->modelData[$this->collection_key][$offset] =
98 new $type($this->modelData[$this->collection_key][$offset]);
99 }
100 }
101 }
102