From 78077e5ce8f82316034d11451653b032c5a8789d Mon Sep 17 00:00:00 2001 From: Max Date: Sat, 11 Jan 2020 19:18:29 +0100 Subject: [PATCH] Changed config usage --- .gitignore | 1 + juggl/config/config.inc.php | 6 ---- juggl/config/config.path.sample | 1 - juggl/config/config.php.sample | 8 +++++ juggl/config/config.txt.sample | 4 --- juggl/services/configReader.inc.php | 54 ----------------------------- juggl/services/dbOperations.inc.php | 10 +++--- 7 files changed, 14 insertions(+), 70 deletions(-) delete mode 100644 juggl/config/config.inc.php delete mode 100644 juggl/config/config.path.sample create mode 100644 juggl/config/config.php.sample delete mode 100644 juggl/config/config.txt.sample delete mode 100644 juggl/services/configReader.inc.php diff --git a/.gitignore b/.gitignore index 79f21cc..c8529c2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ juggl/config/config.txt juggl/config/config.path +juggl/config/config.php diff --git a/juggl/config/config.inc.php b/juggl/config/config.inc.php deleted file mode 100644 index c9eda41..0000000 --- a/juggl/config/config.inc.php +++ /dev/null @@ -1,6 +0,0 @@ -readPathFile(__DIR__."/config.path"); -?> \ No newline at end of file diff --git a/juggl/config/config.path.sample b/juggl/config/config.path.sample deleted file mode 100644 index 35b61a7..0000000 --- a/juggl/config/config.path.sample +++ /dev/null @@ -1 +0,0 @@ -relativepath=config/config.txt \ No newline at end of file diff --git a/juggl/config/config.php.sample b/juggl/config/config.php.sample new file mode 100644 index 0000000..e7fa63d --- /dev/null +++ b/juggl/config/config.php.sample @@ -0,0 +1,8 @@ + "", + "dbname" => "", + "username" => "", + "password" => "", + "table_prefix" => "ju_" +]; \ No newline at end of file diff --git a/juggl/config/config.txt.sample b/juggl/config/config.txt.sample deleted file mode 100644 index b102c26..0000000 --- a/juggl/config/config.txt.sample +++ /dev/null @@ -1,4 +0,0 @@ -host=HOST -dbname=DBNAME -username=USERNAME -password=PASSWORD \ No newline at end of file diff --git a/juggl/services/configReader.inc.php b/juggl/services/configReader.inc.php deleted file mode 100644 index cbe36ab..0000000 --- a/juggl/services/configReader.inc.php +++ /dev/null @@ -1,54 +0,0 @@ -configuration = array(); - } - - function readFile ($path) { - if (file_exists($path) == false) - return; - - $this->configuration = array(); - foreach (file($path) as $line) { - $valuePair = $this->convertLine(trim($line)); - - if ($valuePair === false) - continue; - $this->configuration[$valuePair['key']] = $valuePair['value']; - } - } - - function readPathFile ($pathToPathFile) { - $this->readFile($pathToPathFile); - $this->readFile(__DIR__."/../".$this->getSetting("relativepath")); - } - - function getSetting ($key) { - if (array_key_exists($key, $this->configuration) == false) - return NULL; - - return $this->configuration[$key]; - } - - private function convertLine($line) { - if ($line == "") - return False; - - $splitted = explode (self::VALUE_SEPARATOR, $line, 2); - $key = $splitted[0]; - - $value = ""; - for ($i = 1; $i < sizeof($splitted); $i++) { - if ($i > 1) { - $value .= "="; - } - $value .= $splitted[$i]; - } - - return ['key' => $key, 'value' => $value]; - } -} -?> \ No newline at end of file diff --git a/juggl/services/dbOperations.inc.php b/juggl/services/dbOperations.inc.php index f074ec8..1990fc1 100644 --- a/juggl/services/dbOperations.inc.php +++ b/juggl/services/dbOperations.inc.php @@ -6,11 +6,11 @@ class DbOperations { $this->resetQuery(); $this->tablePrefix = $tablePrefix; - require(__DIR__."/../config/config.inc.php"); + require(__DIR__."/../config/config.php"); $this->config = $config; if ($this->tablePrefix == null) { - $this->tablePrefix = $this->config->getSetting("table_prefix"); + $this->tablePrefix = $this->config["table_prefix"]; } } @@ -22,13 +22,13 @@ class DbOperations { } private function openConnection () { - $host = $this->config->getSetting('host'); - $dbname = $this->config->getSetting('dbname'); + $host = $this->config['host']; + $dbname = $this->config['dbname']; $dsn = "mysql:host=$host;dbname=$dbname"; $options = array(PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC); - $this->pdo = new PDO($dsn, $this->config->getSetting('username'), $this->config->getSetting('password'), $options); + $this->pdo = new PDO($dsn, $this->config['username'], $this->config['password'], $options); } function select (string $table, array $attributes = array()) {