3 declare(strict_types=1);
24 private $indexes = [];
34 if (!is_null($data)) {
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);
127 final protected function addToIndex(
string $field,
string $key,
int $index): void
129 $this->indexes[$field][$key] = $index;
135 final protected function valueByKey(
string $field,
string $key)
137 return isset($this->indexes[$field][$key]) ? $this->
at($this->indexes[$field][$key]) :
null;
142 $keys = !is_null($this->data) ? array_keys($this->data) : [];
143 $keyIterator = new \ArrayIterator(array_combine($keys, $keys));
159 return $this->iterator->current();
167 if ($this->data ==
null) {
170 $arrayKeys = array_keys($this->data);
171 $lastKey = array_pop($arrayKeys);
173 return $this->
at($lastKey);
181 $this->iterator->next();
190 return $this->iterator->key();
198 return $this->iterator->valid();
206 $this->iterator->rewind();
215 return !is_null($this->data) && array_key_exists($offset, $this->data);
224 return $this->
at($offset);
235 $this->
set($value, $offset);
247 unset($this->data[$offset]);