first commit

This commit is contained in:
Maurice Grönwoldt 2020-03-02 10:59:28 +01:00
commit d21ca3e6ab
10 changed files with 753 additions and 0 deletions

129
src/Venom/Config.php Normal file
View file

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

View file

@ -0,0 +1,36 @@
<?php
namespace Venom\Database;
use PDO;
/**
* Singleton DatabaseHandler... make sure we only have one connection to the database..
* @package Venom\Database
*/
class DatabaseHandler
{
private static ?self $instance = null;
private ?PDO $db = null;
public static function get(): DatabaseHandler
{
if (self::$instance === null) {
self::$instance = new self();
}
return self::$instance;
}
public function init(array $data): void
{
//init instance with the current data... only working if the db is not init!
if ($this->db != null) {
return;
}
$dsn = '%s:host=%s;dbname=%s;port=%s';
}
}

View file

@ -0,0 +1,48 @@
<?php
namespace Venom\Database;
/**
* Database Object to use queries like this $obj->id, $obj->value
* also the option to print it in csv format ; as delimiter
* @package Venom\Database
*/
class DatabaseObject
{
/**
* assoc array
* @var array
*/
private $data = [];
public function __get($name)
{
if (isset($this->data[$name])) {
return $this->data[$name];
}
return null;
}
public function __set($name, $value)
{
$this->data[$name] = $value;
}
public function __isset($name)
{
return isset($this->data[$name]);
}
public function toString()
{
return implode(';', $this->data);
}
public function getHead()
{
$keys = array_keys($this->data);
return implode(';', $keys);
}
}

10
src/Venom/Venom.php Normal file
View file

@ -0,0 +1,10 @@
<?php
namespace Venom;
class Venom
{
}

0
src/modules/.gitkeep Normal file
View file