PluginProbe
Media Cloud Sync / 1.4.1
Media Cloud Sync v1.4.1
1.4.1 1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 All 35 releases
media-cloud-sync / includes / sdk / google / ramsey / collection / src / AbstractArray.php

AbstractArray.php in Media Cloud Sync 1.4.1, at includes/sdk/google/ramsey/collection/src/AbstractArray.php

156 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * This file is part of the ramsey/collection library
5 *
6 * For the full copyright and license information, please view the LICENSE
7 * file that was distributed with this source code.
8 *
9 * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com>
10 * @license http://opensource.org/licenses/MIT MIT
11 */
12 declare (strict_types=1);
13 namespace Dudlewebs\WPMCS\GCP\Ramsey\Collection;
14
15 use ArrayIterator;
16 use Traversable;
17 use function count;
18 /**
19 * This class provides a basic implementation of `ArrayInterface`, to minimize
20 * the effort required to implement this interface.
21 *
22 * @template T
23 * @implements ArrayInterface<T>
24 */
25 abstract class AbstractArray implements ArrayInterface
26 {
27 /**
28 * The items of this array.
29 *
30 * @var array<array-key, T>
31 */
32 protected array $data = [];
33 /**
34 * Constructs a new array object.
35 *
36 * @param array<array-key, T> $data The initial items to add to this array.
37 */
38 public function __construct(array $data = [])
39 {
40 // Invoke offsetSet() for each value added; in this way, subclasses
41 // may provide additional logic about values added to the array object.
42 foreach ($data as $key => $value) {
43 $this[$key] = $value;
44 }
45 }
46 /**
47 * Returns an iterator for this array.
48 *
49 * @link http://php.net/manual/en/iteratoraggregate.getiterator.php IteratorAggregate::getIterator()
50 *
51 * @return Traversable<array-key, T>
52 */
53 public function getIterator() : Traversable
54 {
55 return new ArrayIterator($this->data);
56 }
57 /**
58 * Returns `true` if the given offset exists in this array.
59 *
60 * @link http://php.net/manual/en/arrayaccess.offsetexists.php ArrayAccess::offsetExists()
61 *
62 * @param array-key $offset The offset to check.
63 */
64 public function offsetExists(mixed $offset) : bool
65 {
66 return isset($this->data[$offset]);
67 }
68 /**
69 * Returns the value at the specified offset.
70 *
71 * @link http://php.net/manual/en/arrayaccess.offsetget.php ArrayAccess::offsetGet()
72 *
73 * @param array-key $offset The offset for which a value should be returned.
74 *
75 * @return T the value stored at the offset, or null if the offset
76 * does not exist.
77 */
78 public function offsetGet(mixed $offset) : mixed
79 {
80 return $this->data[$offset];
81 }
82 /**
83 * Sets the given value to the given offset in the array.
84 *
85 * @link http://php.net/manual/en/arrayaccess.offsetset.php ArrayAccess::offsetSet()
86 *
87 * @param array-key | null $offset The offset to set. If `null`, the value
88 * may be set at a numerically-indexed offset.
89 * @param T $value The value to set at the given offset.
90 */
91 public function offsetSet(mixed $offset, mixed $value) : void
92 {
93 if ($offset === null) {
94 $this->data[] = $value;
95 } else {
96 $this->data[$offset] = $value;
97 }
98 }
99 /**
100 * Removes the given offset and its value from the array.
101 *
102 * @link http://php.net/manual/en/arrayaccess.offsetunset.php ArrayAccess::offsetUnset()
103 *
104 * @param array-key $offset The offset to remove from the array.
105 */
106 public function offsetUnset(mixed $offset) : void
107 {
108 unset($this->data[$offset]);
109 }
110 /**
111 * Returns data suitable for PHP serialization.
112 *
113 * @link https://www.php.net/manual/en/language.oop5.magic.php#language.oop5.magic.serialize
114 * @link https://www.php.net/serialize
115 *
116 * @return array<array-key, T>
117 */
118 public function __serialize() : array
119 {
120 return $this->data;
121 }
122 /**
123 * Adds unserialized data to the object.
124 *
125 * @param array<array-key, T> $data
126 */
127 public function __unserialize(array $data) : void
128 {
129 $this->data = $data;
130 }
131 /**
132 * Returns the number of items in this array.
133 *
134 * @link http://php.net/manual/en/countable.count.php Countable::count()
135 */
136 public function count() : int
137 {
138 return count($this->data);
139 }
140 public function clear() : void
141 {
142 $this->data = [];
143 }
144 /**
145 * @inheritDoc
146 */
147 public function toArray() : array
148 {
149 return $this->data;
150 }
151 public function isEmpty() : bool
152 {
153 return $this->data === [];
154 }
155 }
156