updated comment, cleaner names

This commit is contained in:
tracer 2022-10-21 19:54:23 +02:00
parent 98e6c7fc64
commit 7d15313503
1 changed files with 11 additions and 12 deletions

View File

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