summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorConvertor <somefakeness@gmail.com>2015-09-08 17:48:43 +0200
committerConvertor <somefakeness@gmail.com>2015-09-08 17:48:43 +0200
commitb9cfafe291d917a128e69dac625b42f35d193be7 (patch)
tree8757177ca12e10bea665056b29944b836bef23f1
parent830f28be94464588db4e86bb10253a8aa47b1101 (diff)
downloadPHPAuth-b9cfafe291d917a128e69dac625b42f35d193be7.zip
PHPAuth-b9cfafe291d917a128e69dac625b42f35d193be7.tar.gz
PHPAuth-b9cfafe291d917a128e69dac625b42f35d193be7.tar.bz2
update config class, need to keep it simple and clean
-rwxr-xr-xconfig.class.php47
1 files changed, 18 insertions, 29 deletions
diff --git a/config.class.php b/config.class.php
index 193b60c..8762a3e 100755
--- a/config.class.php
+++ b/config.class.php
@@ -1,34 +1,24 @@
<?php
-
-/**
- * PHPAuth config class
- */
class Config
{
private $dbh;
private $config;
- private $phpauth_config_table = 'config';
/**
- * Construct Config class, that contains all configuration values.
+ * Config::__construct()
*
- * It is a little trick: we can call '$config = new Config($dbh, "config_table");' always or
- * we can patch private $phpauth_config_table manually and calls '$config = new Config($dbh);'
- * without any additional values!
- * @param \PDO $dbh -- PDO database connect handler
- * @param string $config_table -- config table name
+ * @param mixed $dbh
+ * @param string $config_table
+ * @return
*/
public function __construct(\PDO $dbh, $config_table = 'config')
{
$this->dbh = $dbh;
+ $this->phpauth_config_table = $config_table;
- if (func_num_args() > 1)
- $this->phpauth_config_table = $config_table;
-
$this->config = array();
- $query = $this->dbh->prepare("SELECT * FROM {$this->phpauth_config_table}");
- $query->execute();
+ $query = $this->dbh->query("SELECT * FROM {$this->phpauth_config_table}");
while($row = $query->fetch()) {
$this->config[$row['setting']] = $row['value'];
@@ -36,9 +26,10 @@ class Config
}
/**
- * Return config value
- * @param $setting -- key
- * @return mixed -- config value
+ * Config::__get()
+ *
+ * @param mixed $setting
+ * @return
*/
public function __get($setting)
{
@@ -46,10 +37,11 @@ class Config
}
/**
- * Set config value
- * @param $setting -- key
- * @param $value -- config value
- * @return bool -- true if no any errors occured
+ * Config::__set()
+ *
+ * @param mixed $setting
+ * @param mixed $value
+ * @return
*/
public function __set($setting, $value)
{
@@ -58,10 +50,7 @@ class Config
if($query->execute(array($value, $setting))) {
$this->config[$setting] = $value;
return true;
- } else {
- return false;
- }
+ }
+ return false;
}
-}
-
-?>
+} \ No newline at end of file