summaryrefslogtreecommitdiff
path: root/public/index.php
diff options
context:
space:
mode:
Diffstat (limited to 'public/index.php')
-rw-r--r--public/index.php38
1 files changed, 38 insertions, 0 deletions
diff --git a/public/index.php b/public/index.php
new file mode 100644
index 0000000..4e18b9a
--- /dev/null
+++ b/public/index.php
@@ -0,0 +1,38 @@
+<?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();
+
+$todos = new TodoRepository($config['path_to_repository']);
+
+$template = new Template($config['path_to_templates']);
+
+$sort = $_GET['sort'] ?? 'asc';
+
+$tag = $_GET['tag'] ?? null;
+
+if ($tag !== null) {
+ $todos->filter($tag);
+}
+
+$todos->sort($sort === 'asc');
+
+$message = $session->get('message');
+
+$html = $template->render('index', compact(
+ 'todos',
+ 'message'
+));
+
+respondAndExit(200, 'OK', $html);