1
0
mirror of https://github.com/RSS-Bridge/rss-bridge.git synced 2025-07-30 21:30:14 +02:00

refactor: introduce DI container (#4238)

* refactor: introduce DI container

* add bin/test
This commit is contained in:
Dag
2024-08-29 22:48:59 +02:00
committed by GitHub
parent e010fd4d52
commit 58544cd61a
18 changed files with 231 additions and 89 deletions

33
lib/Container.php Normal file
View File

@@ -0,0 +1,33 @@
<?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;
}
#[ReturnTypeWillChange] public function offsetGet($offset)
{
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];
}
#[ReturnTypeWillChange] public function offsetExists($offset)
{
}
public function offsetUnset($offset): void
{
}
}