basic website, basic templating

This commit is contained in:
2022-10-21 14:31:48 +02:00
parent 303fc11327
commit fdd24d90da
11 changed files with 196 additions and 0 deletions

33
src/Service/Container.php Normal file

@ -0,0 +1,33 @@
<?php
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
private Template $template;
private AddressBook $addressBook;
public function __construct()
{
$this->template = new Template(templateDir: dirname(path: __DIR__, levels: 2) . '/templates/');
$this->addressBook = new AddressBook(template: $this->template);
}
/**
* @throws Exception
*/
public function get(string $class): stdClass
{
return match($class) {
'App\Controller\AddressBook' => $this->addressBook,
default => throw new Exception(message: "Missing class definition: $class")
};
}
}