2024-08-29 23:48:59 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
class Container implements \ArrayAccess
|
|
|
|
{
|
|
|
|
private array $values = [];
|
|
|
|
private array $resolved = [];
|
|
|
|
|
|
|
|
public function offsetSet($offset, $value): void
|
|
|
|
{
|
|
|
|
$this->values[$offset] = $value;
|
|
|
|
}
|
|
|
|
|
2024-08-30 00:02:01 +03:00
|
|
|
#[\ReturnTypeWillChange]
|
|
|
|
public function offsetGet($offset)
|
2024-08-29 23:48:59 +03:00
|
|
|
{
|
|
|
|
if (!isset($this->values[$offset])) {
|
|
|
|
throw new \Exception(sprintf('Unknown container key: "%s"', $offset));
|
|
|
|
}
|
|
|
|
if (!isset($this->resolved[$offset])) {
|
|
|
|
$this->resolved[$offset] = $this->values[$offset]($this);
|
|
|
|
}
|
|
|
|
return $this->resolved[$offset];
|
|
|
|
}
|
|
|
|
|
2024-08-30 00:02:01 +03:00
|
|
|
#[\ReturnTypeWillChange]
|
|
|
|
public function offsetExists($offset)
|
2024-08-29 23:48:59 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public function offsetUnset($offset): void
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|