From 7d153135037c538aaa1f417596cb46c8d29a88e5 Mon Sep 17 00:00:00 2001 From: tracer Date: Fri, 21 Oct 2022 19:54:23 +0200 Subject: [PATCH] updated comment, cleaner names --- src/Service/Container.php | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/Service/Container.php b/src/Service/Container.php index 440bb0b..84d9a7c 100644 --- a/src/Service/Container.php +++ b/src/Service/Container.php @@ -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") }; } } \ No newline at end of file