venom/src/Venom/Config.php

131 lines
2.8 KiB
PHP

<?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;
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
{
if ($this->isWriteable) {
$this->api = $array;
} else {
trigger_error('try to write closed config!');
}
}
public function setRender(array $array): void
{
if ($this->isWriteable) {
$this->renderer = $array;
} else {
trigger_error('try to write closed config!');
}
}
public function setMaintainMode(bool $mode): void
{
if ($this->isWriteable) {
$this->maintenance = $mode;
} else {
trigger_error('try to write closed config!');
}
}
public function getVersion(): float
{
return $this->version;
}
public function setVersion(float $param): void
{
if ($this->isWriteable) {
$this->version = $param;
} else {
trigger_error('try to write closed config!');
}
}
public function getApi(): array
{
return $this->api;
}
public function getMail(): array
{
return $this->mail;
}
public function setMail(array $array): void
{
if ($this->isWriteable) {
$this->mail = $array;
} else {
trigger_error('try to write closed config!');
}
}
public function getRenderer(): array
{
return $this->renderer;
}
public function isMaintenance(): bool
{
return $this->maintenance;
}
public function isDevMode(): bool
{
return $this->devMode;
}
public function setDevMode(bool $mode): void
{
if ($this->isWriteable) {
$this->devMode = $mode;
} else {
trigger_error('try to write closed config!');
}
}
/**
* 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;
}
}