32 lines
959 B
PHP

<?php
namespace App\Service;
use App\Controller\AddressBook;
class Container
{
// caveat: Classes are always instantiated
// No autowiring (yet, maybe later, but it might fit for a demo)
private Template $template;
private AddressBook $addressBook;
private Router $router;
public function __construct()
{
$this->template = new Template(templateDir: dirname(path: __DIR__, levels: 2) . '/templates/');
$this->addressBook = new AddressBook(template: $this->template);
$this->router = new Router();
}
public function get(string $className): object
{
return match ($className) {
'App\Controller\AddressBook' => $this->addressBook,
'App\Service\Router' => $this->router,
//default => throw new Exception(message: "Missing class definition: $class")
default => die("Missing class definition: $className")
};
}
}