Add options class

This commit is contained in:
Jay Trees 2022-01-14 10:50:48 +01:00
parent e1802a187c
commit 44ef02aa17
4 changed files with 36 additions and 13 deletions

View file

@ -37,14 +37,4 @@ class Database
\PDO::FETCH_ASSOC
);
}
public function getOption(string $key): string
{
$option = $this->query(
'SELECT * FROM `options`
WHERE `key` = "' . $key . '";'
)->fetch();
return $option['value'];
}
}

View file

@ -0,0 +1,28 @@
<?php
/**
* options.php
*
* Store and retrieve application options.
*
* @author Jay Trees <github.jay@grandel.anonaddy.me>
*/
namespace wishthis;
class Options
{
public function __construct(private Database $database)
{
}
public function getOption(string $key): string
{
$option = $this->database->query(
'SELECT * FROM `options`
WHERE `key` = "' . $key . '";'
)->fetch();
return $option['value'];
}
}

View file

@ -8,7 +8,7 @@
use wishthis\{Page, Database};
if ($database->getOption('isInstalled')) {
if ($options->getOption('isInstalled')) {
header('Location: /?page=login');
die();
}

View file

@ -42,6 +42,11 @@ if (
);
}
/**
* Options
*/
$options = new wishthis\Options($database);
/**
* Session
*/
@ -57,9 +62,9 @@ if (isset($api)) {
/**
* Install
*/
if ($database) {
if ($options) {
try {
$database->getOption('isInstalled');
$options->getOption('isInstalled');
} catch (\Throwable $th) {
$page = 'install';
}