AccessToken
5 days ago
AuthHandler
5 days ago
Http
5 days ago
Service
5 days ago
Task
5 days ago
Utils
5 days ago
Client.php
5 days ago
Collection.php
5 days ago
Exception.php
5 days ago
Model.php
5 days ago
Service.php
5 days ago
aliases.php
5 days ago
Collection.php
105 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPMailSMTP\Vendor\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 | /** @return void */ |
| 14 | #[\ReturnTypeWillChange] |
| 15 | public function rewind() |
| 16 | { |
| 17 | if (isset($this->{$this->collection_key}) && \is_array($this->{$this->collection_key})) { |
| 18 | \reset($this->{$this->collection_key}); |
| 19 | } |
| 20 | } |
| 21 | /** @return mixed */ |
| 22 | #[\ReturnTypeWillChange] |
| 23 | public function current() |
| 24 | { |
| 25 | $this->coerceType($this->key()); |
| 26 | if (\is_array($this->{$this->collection_key})) { |
| 27 | return \current($this->{$this->collection_key}); |
| 28 | } |
| 29 | } |
| 30 | /** @return mixed */ |
| 31 | #[\ReturnTypeWillChange] |
| 32 | public function key() |
| 33 | { |
| 34 | if (isset($this->{$this->collection_key}) && \is_array($this->{$this->collection_key})) { |
| 35 | return \key($this->{$this->collection_key}); |
| 36 | } |
| 37 | } |
| 38 | /** @return mixed */ |
| 39 | #[\ReturnTypeWillChange] |
| 40 | public function next() |
| 41 | { |
| 42 | return \next($this->{$this->collection_key}); |
| 43 | } |
| 44 | /** @return bool */ |
| 45 | #[\ReturnTypeWillChange] |
| 46 | public function valid() |
| 47 | { |
| 48 | $key = $this->key(); |
| 49 | return $key !== null && $key !== \false; |
| 50 | } |
| 51 | /** @return int */ |
| 52 | #[\ReturnTypeWillChange] |
| 53 | public function count() |
| 54 | { |
| 55 | if (!isset($this->{$this->collection_key})) { |
| 56 | return 0; |
| 57 | } |
| 58 | return \count($this->{$this->collection_key}); |
| 59 | } |
| 60 | /** @return bool */ |
| 61 | #[\ReturnTypeWillChange] |
| 62 | public function offsetExists($offset) |
| 63 | { |
| 64 | if (!\is_numeric($offset)) { |
| 65 | return parent::offsetExists($offset); |
| 66 | } |
| 67 | return isset($this->{$this->collection_key}[$offset]); |
| 68 | } |
| 69 | /** @return mixed */ |
| 70 | #[\ReturnTypeWillChange] |
| 71 | public function offsetGet($offset) |
| 72 | { |
| 73 | if (!\is_numeric($offset)) { |
| 74 | return parent::offsetGet($offset); |
| 75 | } |
| 76 | $this->coerceType($offset); |
| 77 | return $this->{$this->collection_key}[$offset]; |
| 78 | } |
| 79 | /** @return void */ |
| 80 | #[\ReturnTypeWillChange] |
| 81 | public function offsetSet($offset, $value) |
| 82 | { |
| 83 | if (!\is_numeric($offset)) { |
| 84 | parent::offsetSet($offset, $value); |
| 85 | } |
| 86 | $this->{$this->collection_key}[$offset] = $value; |
| 87 | } |
| 88 | /** @return void */ |
| 89 | #[\ReturnTypeWillChange] |
| 90 | public function offsetUnset($offset) |
| 91 | { |
| 92 | if (!\is_numeric($offset)) { |
| 93 | parent::offsetUnset($offset); |
| 94 | } |
| 95 | unset($this->{$this->collection_key}[$offset]); |
| 96 | } |
| 97 | private function coerceType($offset) |
| 98 | { |
| 99 | $keyType = $this->keyType($this->collection_key); |
| 100 | if ($keyType && !\is_object($this->{$this->collection_key}[$offset])) { |
| 101 | $this->{$this->collection_key}[$offset] = new $keyType($this->{$this->collection_key}[$offset]); |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 |