blog/app/Core/container.php
2025-03-07 10:04:42 +00:00

18 lines
384 B
PHP

<?php
namespace Blog\Core;
class Container {
private array $instances = [];
public function set(string $key, callable $factory): void {
$this->instances[$key] = $factory;
}
public function get(string $key): mixed {
if(!isset($this->instances[$key])) {
throw new Exception("No instance found for {$key}");
}
return $this->instances[$key]($this);
}
}