diff options
Diffstat (limited to 'public/view/index.php')
| -rw-r--r-- | public/view/index.php | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/public/view/index.php b/public/view/index.php new file mode 100644 index 0000000..798cefd --- /dev/null +++ b/public/view/index.php @@ -0,0 +1,37 @@ +<?php + +declare(strict_types=1); + +use DTS\TodoRepository; +use DTS\Session; +use DTS\Template; + +use function DTS\Functions\respondAndExit; + +require_once(__DIR__.'/../../autoload.php'); + +$config = require_once(__DIR__.'/../../config.php'); + +$session = Session::getInstance(); + +if (filter_input(INPUT_SERVER, 'REQUEST_METHOD') !== 'GET') { + respondAndExit(405, 'Method Not Allowed'); +} + +$id = filter_input(INPUT_GET, 'id'); + +$todos = new TodoRepository($config['path_to_repository']); + +$template = new Template($config['path_to_templates']); + +$todo = $todos->find($id); + +if ($todo === null) { + respondAndExit(404, 'Not Found'); +} + +$html = $template->render('view', compact( + 'todo' +)); + +respondAndExit(200, 'OK', $html); |
