3 declare(strict_types=1);
23 private $indexes = [];
33 if (!is_null($data)) {
45 #[\ReturnTypeWillChange]
58 return new static($data);
64 protected function index($data): void
71 final protected function get(?
int $index)
73 if (isset($this->data[$index])) {
74 return $this->data[$index];
82 final protected function set($data, ?
int $index):
void
84 if (is_null($index)) {
85 $this->data[] = $data;
87 $this->data[$index] = $data;
96 public function add($value)
98 return $this->
store($value);
106 final protected function store($value)
108 $this->
set($value,
null);
117 public function at(
int $index)
119 return $this->
mapper()($index);
130 final protected function addToIndex(
string $field,
string $key,
int $index): void
132 $this->indexes[$field][$key] = $index;
138 final protected function valueByKey(
string $field,
string $key)
140 return isset($this->indexes[$field][$key]) ? $this->
at($this->indexes[$field][$key]) :
null;
145 $keys = !is_null($this->data) ? array_keys($this->data) : [];
146 $keyIterator = new \ArrayIterator(array_combine($keys, $keys));
162 return $this->iterator->current();
170 if ($this->data ==
null) {
173 $arrayKeys = array_keys($this->data);
174 $lastKey = array_pop($arrayKeys);
176 return $this->
at($lastKey);
184 $this->iterator->next();
193 return $this->iterator->key();
201 return $this->iterator->valid();
209 $this->iterator->rewind();
218 return !is_null($this->data) && array_key_exists($offset, $this->data);
227 return $this->
at($offset);
238 $this->
set($value, $offset);
250 unset($this->data[$offset]);
258 final public static function of()