first commit
This commit is contained in:
17
app/Core/container.php
Normal file
17
app/Core/container.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user