PluginProbe ʕ •ᴥ•ʔ
Atarim – Visual Feedback, Review & AI Collaboration / 4.2
Atarim – Visual Feedback, Review & AI Collaboration v4.2
trunk 3.10 3.11 3.12 3.13 3.14 3.15 3.16 3.17 3.18 3.19 3.2.0 3.2.1 3.22 3.22.1 3.22.2 3.22.3 3.22.4 3.22.5 3.22.6 3.3.0 3.3.1 3.3.2 3.3.2.1 3.3.2.2 3.3.3 3.30 3.31 3.32 3.4 3.4.1 3.4.3 3.4.4 3.5 3.5.1 3.6 3.6.1 3.7 3.8 3.9 3.9.1 3.9.2 3.9.3 3.9.4 3.9.6 3.9.6.1 4.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.0.9 4.1.0 4.1.1 4.1.2 4.1.3 4.2 4.2.1 4.2.2 4.3 4.3.1 4.3.2 4.3.3 4.3.4 4.3.5 4.4
atarim-visual-collaboration / src / Collection.php
atarim-visual-collaboration / src Last commit date
AccessToken 1 year ago AuthHandler 1 year ago Http 1 year ago Service 1 year ago Task 1 year ago Utils 1 year ago Client.php 1 year ago Collection.php 1 year ago Exception.php 1 year ago Model.php 1 year ago Service.php 1 year ago aliases.php 1 year ago
Collection.php
122 lines
1 <?php
2
3 namespace Google;
4
5 /**
6 * Extension to the regular Google\Model that automatically
7 * exposes the items array for iteration, so you can just
8 * iterate over the object rather than a reference inside.
9 */
10 class Collection extends Model implements \Iterator, \Countable
11 {
12 protected $collection_key = 'items';
13
14 /** @return void */
15 #[\ReturnTypeWillChange]
16 public function rewind()
17 {
18 if (
19 isset($this->{$this->collection_key})
20 && is_array($this->{$this->collection_key})
21 ) {
22 reset($this->{$this->collection_key});
23 }
24 }
25
26 /** @return mixed */
27 #[\ReturnTypeWillChange]
28 public function current()
29 {
30 $this->coerceType($this->key());
31 if (is_array($this->{$this->collection_key})) {
32 return current($this->{$this->collection_key});
33 }
34 }
35
36 /** @return mixed */
37 #[\ReturnTypeWillChange]
38 public function key()
39 {
40 if (
41 isset($this->{$this->collection_key})
42 && is_array($this->{$this->collection_key})
43 ) {
44 return key($this->{$this->collection_key});
45 }
46 }
47
48 /** @return mixed */
49 #[\ReturnTypeWillChange]
50 public function next()
51 {
52 return next($this->{$this->collection_key});
53 }
54
55 /** @return bool */
56 #[\ReturnTypeWillChange]
57 public function valid()
58 {
59 $key = $this->key();
60 return $key !== null && $key !== false;
61 }
62
63 /** @return int */
64 #[\ReturnTypeWillChange]
65 public function count()
66 {
67 if (!isset($this->{$this->collection_key})) {
68 return 0;
69 }
70 return count($this->{$this->collection_key});
71 }
72
73 /** @return bool */
74 #[\ReturnTypeWillChange]
75 public function offsetExists($offset)
76 {
77 if (!is_numeric($offset)) {
78 return parent::offsetExists($offset);
79 }
80 return isset($this->{$this->collection_key}[$offset]);
81 }
82
83 /** @return mixed */
84 public function offsetGet($offset)
85 {
86 if (!is_numeric($offset)) {
87 return parent::offsetGet($offset);
88 }
89 $this->coerceType($offset);
90 return $this->{$this->collection_key}[$offset];
91 }
92
93 /** @return void */
94 #[\ReturnTypeWillChange]
95 public function offsetSet($offset, $value)
96 {
97 if (!is_numeric($offset)) {
98 parent::offsetSet($offset, $value);
99 }
100 $this->{$this->collection_key}[$offset] = $value;
101 }
102
103 /** @return void */
104 #[\ReturnTypeWillChange]
105 public function offsetUnset($offset)
106 {
107 if (!is_numeric($offset)) {
108 parent::offsetUnset($offset);
109 }
110 unset($this->{$this->collection_key}[$offset]);
111 }
112
113 private function coerceType($offset)
114 {
115 $keyType = $this->keyType($this->collection_key);
116 if ($keyType && !is_object($this->{$this->collection_key}[$offset])) {
117 $this->{$this->collection_key}[$offset] =
118 new $keyType($this->{$this->collection_key}[$offset]);
119 }
120 }
121 }
122