More over engineering.
TBH at this point I think I need a DI container.
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
<?php
|
||||
|
||||
use FooBar\Configuration;
|
||||
use FooBar\ReadableState;
|
||||
use FooBar\State;
|
||||
|
||||
require_once '../vendor/autoload.php';
|
||||
|
||||
$config = Configuration::loadConfig();
|
||||
$state = new State($config);
|
||||
|
||||
function auth_check(Configuration $config)
|
||||
{
|
||||
@@ -12,26 +15,22 @@ function auth_check(Configuration $config)
|
||||
http_response_code(403);
|
||||
}
|
||||
|
||||
|
||||
echo 'Some text otherwise PHP crashes. I wish this was a joke.';
|
||||
}
|
||||
|
||||
function toggle(Configuration $config)
|
||||
function toggle(Configuration $config, State $state)
|
||||
{
|
||||
if ($config->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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user