3 declare(strict_types=1);
23 private $indexes = [];
33 if (!is_null($data)) {
45 final public static function of($data =
null)
47 if (is_array($data)) {
62 #[\ReturnTypeWillChange]
79 return new static($t);
89 return new static($data);
95 protected function index($data): void
102 final protected function get(
string $key)
104 if (isset($this->data[$key])) {
105 return $this->data[$key];
113 final protected function set($data,
string $key):
void
115 $this->data[$key] = $data;
123 public function put(
string $key, $value)
125 return $this->
store($key, $value);
134 final protected function store(
string $key, $value)
136 $this->
set($value, $key);
145 public function at(
string $key)
147 return $this->
mapper()($key);
153 public function with(
string $key, callable $callable =
null)
155 $data = $this->
at($key);
156 if (is_null($callable)) {
160 return $callable($data);
171 final protected function addToIndex(
string $field,
string $key,
string $indexKey): void
173 $this->indexes[$field][$key] = $indexKey;
179 final protected function valueByKey(
string $field,
string $key)
181 return isset($this->indexes[$field][$key]) ? $this->
at($this->indexes[$field][$key]) :
null;
186 $keys = !is_null($this->data) ? array_keys($this->data) : [];
187 $keyIterator = new \ArrayIterator(array_combine($keys, $keys));
203 return $this->iterator->current();
211 $this->iterator->next();
220 return $this->iterator->key();
228 return $this->iterator->valid();
236 $this->iterator->rewind();
245 return !is_null($this->data) && array_key_exists($offset, $this->data);
254 return $this->
at($offset);
265 $this->
store($offset, $value);
276 unset($this->data[$offset]);