Files
isdefoobaropen/public/index.php
Bert Peters 650b7ee48c More over engineering.
TBH at this point I think I need a DI container.
2019-03-27 15:29:06 +01:00

49 lines
982 B
PHP

<?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)
{
if (!$config->isAuthorized()) {
http_response_code(403);
}
echo 'Some text otherwise PHP crashes. I wish this was a joke.';
}
function toggle(Configuration $config, State $state)
{
if ($config->isAuthorized()) {
$state->toggle();
}
header('location: ' . $_SERVER['REQUEST_URI']);
}
function display_state(ReadableState $state)
{
$open = $state->isOpen();
header('X-Foobar-Open: ' . var_export($open, true));
if ($open) {
require '../templates/open.html';
} else {
require '../templates/closed.html';
}
}
if (isset($_POST['auth_check'])) {
auth_check($config);
} elseif (isset($_POST['toggle'])) {
toggle($config, $state);
} else {
display_state($state);
}