Files
lucent-laravel/src/ArrayContainer.php
T

56 lines
1.0 KiB
PHP
Raw Normal View History

2023-10-02 23:10:49 +03:00
<?php
namespace Lucent;
use ArrayAccess;
use JsonSerializable;
/**
* @implements ArrayAccess<string,mixed>
*/
class ArrayContainer implements ArrayAccess, JsonSerializable
{
public function __construct(public array $data)
{
}
public function get(string $key, mixed $default = null): mixed
{
return $this->data[$key] ?? $default;
}
public function offsetSet($offset, $value): void
{
if (is_null($offset)) {
$this->data[] = $value;
} else {
$this->data[$offset] = $value;
}
}
public function offsetExists($offset): bool
{
return isset($this->data[$offset]);
}
public function offsetUnset($offset): void
{
unset($this->data[$offset]);
}
public function offsetGet($offset): mixed
{
return $this->data[$offset] ?? null;
}
public function jsonSerialize(): array
{
return $this->data;
}
public function toArray(): array
{
return $this->data;
}
}