18 lines
384 B
PHP
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);
|
|
}
|
|
}
|