chore: lots of changes

This commit is contained in:
2025-05-24 07:09:22 +02:00
parent 77ee769d5e
commit 899227b0a4
178 changed files with 5145 additions and 53 deletions

View File

@@ -0,0 +1,47 @@
<?php
declare(strict_types=1);
namespace App\Framework\DI;
use App\Framework\Attributes\Singleton;
class Container
{
private array $singletons = [];
public function __construct(private array $definitions)
{
}
public function get(string $class): object
{
if (isset($this->singletons[$class])) {
return $this->singletons[$class];
}
$reflection = new \ReflectionClass($class);
$constructor = $reflection->getConstructor();
$dependencies = [];
if ($constructor !== null) {
foreach ($constructor->getParameters() as $param) {
$type = $param->getType();
if (!$type || $type->isBuiltin()) {
throw new \RuntimeException("Cannot resolve parameter {$param->getName()}");
}
$dependencies[] = $this->get($type->getName());
}
}
$instance = $reflection->newInstanceArgs($dependencies);
if ($reflection->getAttributes(Singleton::class)) {
$this->singletons[$class] = $instance;
}
return $instance;
}
}