2020-03-02 10:59:28 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Venom;
|
|
|
|
|
|
|
|
use Venom\Database\DatabaseHandler;
|
|
|
|
|
|
|
|
class Config
|
|
|
|
{
|
|
|
|
private static ?Config $instance = null;
|
|
|
|
private bool $isWriteable = true;
|
|
|
|
private float $version = 1.0;
|
|
|
|
private array $api = [];
|
|
|
|
private array $mail = [];
|
|
|
|
private array $renderer = [];
|
|
|
|
private bool $maintenance = false;
|
|
|
|
private bool $devMode = false;
|
2020-05-31 17:00:05 +02:00
|
|
|
private bool $isAdmin = false;
|
|
|
|
private string $baseUrl = '';
|
2020-07-24 11:08:07 +02:00
|
|
|
private bool $seoMode = false;
|
2020-03-02 10:59:28 +01:00
|
|
|
|
|
|
|
private function __construct()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getInstance(): Config
|
|
|
|
{
|
|
|
|
if (self::$instance === null) {
|
|
|
|
self::$instance = new Config();
|
|
|
|
}
|
|
|
|
return self::$instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setDatabase(array $array): void
|
|
|
|
{
|
|
|
|
if ($this->isWriteable) {
|
|
|
|
DatabaseHandler::get()->init($array);
|
|
|
|
} else {
|
|
|
|
trigger_error('try to write closed config!');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setAPIAuth(array $array): void
|
|
|
|
{
|
2020-05-31 17:00:05 +02:00
|
|
|
$this->set('api', $array);
|
2020-03-02 10:59:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function setRender(array $array): void
|
|
|
|
{
|
2020-05-31 17:00:05 +02:00
|
|
|
$this->set('renderer', $array);
|
2020-03-02 10:59:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function setMaintainMode(bool $mode): void
|
|
|
|
{
|
2020-05-31 17:00:05 +02:00
|
|
|
$this->set('maintenance', $mode);
|
2020-03-02 10:59:28 +01:00
|
|
|
}
|
|
|
|
|
2020-03-28 20:11:51 +01:00
|
|
|
public function getVersion(): float
|
2020-03-02 10:59:28 +01:00
|
|
|
{
|
2020-03-28 20:11:51 +01:00
|
|
|
return $this->version;
|
2020-03-02 10:59:28 +01:00
|
|
|
}
|
|
|
|
|
2020-03-28 20:11:51 +01:00
|
|
|
public function setVersion(float $param): void
|
2020-03-02 10:59:28 +01:00
|
|
|
{
|
2020-05-31 17:00:05 +02:00
|
|
|
$this->set('version', $param);
|
2020-03-02 10:59:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getApi(): array
|
|
|
|
{
|
|
|
|
return $this->api;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getMail(): array
|
|
|
|
{
|
|
|
|
return $this->mail;
|
|
|
|
}
|
|
|
|
|
2020-03-28 20:11:51 +01:00
|
|
|
public function setMail(array $array): void
|
|
|
|
{
|
2020-05-31 17:00:05 +02:00
|
|
|
$this->set('mail', $array);
|
2020-03-28 20:11:51 +01:00
|
|
|
}
|
|
|
|
|
2020-03-02 10:59:28 +01:00
|
|
|
public function getRenderer(): array
|
|
|
|
{
|
|
|
|
return $this->renderer;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isMaintenance(): bool
|
|
|
|
{
|
|
|
|
return $this->maintenance;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isDevMode(): bool
|
|
|
|
{
|
|
|
|
return $this->devMode;
|
|
|
|
}
|
|
|
|
|
2020-03-28 20:11:51 +01:00
|
|
|
public function setDevMode(bool $mode): void
|
|
|
|
{
|
2020-05-31 17:00:05 +02:00
|
|
|
$this->set('devMode', $mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isAdmin(): bool
|
|
|
|
{
|
|
|
|
return $this->isAdmin;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param bool $isAdmin
|
|
|
|
*/
|
|
|
|
public function setIsAdmin(bool $isAdmin): void
|
|
|
|
{
|
|
|
|
$this->set('isAdmin', $isAdmin);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setBaseUrl(string $url) {
|
|
|
|
$this->set('baseUrl', $url);
|
|
|
|
}
|
|
|
|
|
2020-07-24 11:08:07 +02:00
|
|
|
public function setSeoMode(bool $mode) {
|
|
|
|
$this->set('seoMode', $mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getSeoEnabled() {
|
|
|
|
return $this->seoMode;
|
|
|
|
}
|
|
|
|
|
2020-05-31 17:00:05 +02:00
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isClosed(): bool
|
|
|
|
{
|
|
|
|
return !$this->isWriteable;
|
2020-03-28 20:11:51 +01:00
|
|
|
}
|
|
|
|
|
2020-03-02 10:59:28 +01:00
|
|
|
/**
|
|
|
|
* function to close the write mode... this make sure after the config is init no other tool can write to it!
|
|
|
|
*/
|
|
|
|
public function close(): void
|
|
|
|
{
|
|
|
|
$this->isWriteable = false;
|
|
|
|
}
|
2020-05-31 17:00:05 +02:00
|
|
|
|
|
|
|
public function set(string $variable, $value) {
|
|
|
|
if (!$this->isWriteable) {
|
|
|
|
trigger_error('try to write closed config!');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$this->$variable = $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getBaseUrl()
|
|
|
|
{
|
|
|
|
return $this->baseUrl;
|
|
|
|
}
|
2020-03-02 10:59:28 +01:00
|
|
|
}
|