Add options class
This commit is contained in:
parent
e1802a187c
commit
44ef02aa17
4 changed files with 36 additions and 13 deletions
|
@ -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'];
|
||||
}
|
||||
}
|
||||
|
|
28
includes/classes/options.php
Normal file
28
includes/classes/options.php
Normal 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'];
|
||||
}
|
||||
}
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
use wishthis\{Page, Database};
|
||||
|
||||
if ($database->getOption('isInstalled')) {
|
||||
if ($options->getOption('isInstalled')) {
|
||||
header('Location: /?page=login');
|
||||
die();
|
||||
}
|
||||
|
|
|
@ -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';
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue