2022-01-14 09:50:48 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* options.php
|
|
|
|
*
|
|
|
|
* Store and retrieve application options.
|
|
|
|
*
|
|
|
|
* @author Jay Trees <github.jay@grandel.anonaddy.me>
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace wishthis;
|
|
|
|
|
|
|
|
class Options
|
|
|
|
{
|
2022-01-14 13:13:07 +00:00
|
|
|
public bool $updateAvailable = false;
|
|
|
|
|
2022-01-17 12:22:47 +00:00
|
|
|
public string $version;
|
|
|
|
|
2022-01-14 09:50:48 +00:00
|
|
|
public function __construct(private Database $database)
|
|
|
|
{
|
2022-01-17 12:22:47 +00:00
|
|
|
$this->version = $this->getOption('version')
|
|
|
|
? $this->getOption('version')
|
|
|
|
: '0.1.0';
|
2022-01-14 09:50:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getOption(string $key): string
|
|
|
|
{
|
2022-01-14 15:18:54 +00:00
|
|
|
$value = '';
|
2022-01-14 09:50:48 +00:00
|
|
|
|
2022-01-14 15:18:54 +00:00
|
|
|
try {
|
|
|
|
$option = $this->database->query(
|
|
|
|
'SELECT * FROM `options`
|
|
|
|
WHERE `key` = "' . $key . '";'
|
|
|
|
)->fetch();
|
|
|
|
|
|
|
|
$value = $option['value'] ?? '';
|
|
|
|
} catch (\Throwable $th) {
|
|
|
|
//throw $th;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $value;
|
2022-01-14 09:50:48 +00:00
|
|
|
}
|
2022-01-18 10:49:37 +00:00
|
|
|
|
|
|
|
public function setOption(string $key, string $value): void
|
|
|
|
{
|
2022-01-18 13:59:43 +00:00
|
|
|
$this->database->query('UPDATE `options`
|
|
|
|
SET `value` = "' . $value . '"
|
|
|
|
WHERE `key` = "' . $key . '"
|
|
|
|
;');
|
2022-01-18 10:49:37 +00:00
|
|
|
}
|
2022-01-14 09:50:48 +00:00
|
|
|
}
|