From 650b7ee48ccedce6f100a45069d656f55389e6e8 Mon Sep 17 00:00:00 2001 From: Bert Peters Date: Wed, 27 Mar 2019 15:29:06 +0100 Subject: [PATCH] More over engineering. TBH at this point I think I need a DI container. --- public/index.php | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/public/index.php b/public/index.php index df9d99c..61a12d2 100644 --- a/public/index.php +++ b/public/index.php @@ -1,10 +1,13 @@ isAuthorized()) { - $file = $config->stateFile(); - if ($config->isOpen()) { - unlink($file); - } else { - touch($file); - } + $state->toggle(); } header('location: ' . $_SERVER['REQUEST_URI']); } -function display_state(bool $open) +function display_state(ReadableState $state) { + $open = $state->isOpen(); + header('X-Foobar-Open: ' . var_export($open, true)); if ($open) { require '../templates/open.html'; @@ -43,7 +42,7 @@ function display_state(bool $open) if (isset($_POST['auth_check'])) { auth_check($config); } elseif (isset($_POST['toggle'])) { - toggle($config); + toggle($config, $state); } else { - display_state($config->isOpen()); + display_state($state); }