summaryrefslogtreecommitdiff
path: root/manager/library/config
diff options
context:
space:
mode:
Diffstat (limited to 'manager/library/config')
-rw-r--r--manager/library/config/Config.php194
-rw-r--r--manager/library/config/Config_Db.php44
-rw-r--r--manager/library/config/Config_Writer_Db.php112
3 files changed, 175 insertions, 175 deletions
diff --git a/manager/library/config/Config.php b/manager/library/config/Config.php
index fe47ae6..2c315a6 100644
--- a/manager/library/config/Config.php
+++ b/manager/library/config/Config.php
@@ -3,101 +3,101 @@
require_once('config/Config_Db.php');
class Config {
- /**
- * static pointer to instances
- * @var array(Config)
- */
- private static $instances = array();
-
- /**
- * can handle several instances, distinct by instance name string
- * @var string
- */
- private $instanceName = '';
-
- /**
- * config object
- * @var Config_Db
- */
- private $config = null;
-
- /**
- * make a new Config_Db
- *
- * by using the $where statement you can limit the data that is fetched from db, i.e. only get config for zone $id
- *
- * @param string $instanceName
- * @param Zend_Db_Adapter $db
- * @param string $where
- */
- protected function __construct($instanceName = null, $db = null, $where = null) {
- if ($instanceName === null)
- throw new Exception(__METHOD__ . ': expected an instance name, got none');
-
- $config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', APPLICATION_ENV);
- $this->instanceName = $instanceName;
-
- if ($db === null)
- $db = Zend_Db::factory($config->dnssecme->db->config->pdo, $config->dnssecme->db->config);
-
- $this->config = new Config_Db($db, $instanceName, $where, true);
- }
-
- /**
- * get already existing instance, make new instance or throw an exception
- * @param string $instanceName
- * @param Zend_Db_Adapter $db
- * @param string $where
- */
- public static function getInstance($instanceName, $db = null, $where = null) {
- if ($instanceName === null)
- throw new Exception(__METHOD__ . ': expected an instance name, got none');
-
- // no caching if presumeably volatile data is requested
- if ($db !== null && $where !== null) {
- return new Config($instanceName, $db, $where);
- }
-
- if (!array_key_exists($instanceName, self::$instances)) {
- self::$instances[$instanceName] = new Config($instanceName, $db, $where);
- }
-
- return self::$instances[$instanceName];
- }
-
- /**
- * magic method that dispatches all unrecognized method calls to the config object
- *
- * @param string $param
- */
- public function __get($param) {
- return $this->config->$param;
- }
-
- /**
- * magic method that handles isset inquiries to attributes
- *
- * @param string $param
- */
- public function __isset($param) {
- return isset($this->config->$param);
- }
-
- /**
- * magic method that dispatches all unrecognized method calls to the config object
- *
- * @param string $param
- * @param string $value
- */
- public function __set($param, $value) {
- $this->config->$param = $value;
- }
-
- /**
- * get the config object
- * @return Zend_Config_*
- */
- public function getConfig() {
- return $this->config;
- }
+ /**
+ * static pointer to instances
+ * @var array(Config)
+ */
+ private static $instances = array();
+
+ /**
+ * can handle several instances, distinct by instance name string
+ * @var string
+ */
+ private $instanceName = '';
+
+ /**
+ * config object
+ * @var Config_Db
+ */
+ private $config = null;
+
+ /**
+ * make a new Config_Db
+ *
+ * by using the $where statement you can limit the data that is fetched from db, i.e. only get config for zone $id
+ *
+ * @param string $instanceName
+ * @param Zend_Db_Adapter $db
+ * @param string $where
+ */
+ protected function __construct($instanceName = null, $db = null, $where = null) {
+ if ($instanceName === null)
+ throw new Exception(__METHOD__ . ': expected an instance name, got none');
+
+ $config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', APPLICATION_ENV);
+ $this->instanceName = $instanceName;
+
+ if ($db === null)
+ $db = Zend_Db::factory($config->dnssecme->db->config->pdo, $config->dnssecme->db->config);
+
+ $this->config = new Config_Db($db, $instanceName, $where, true);
+ }
+
+ /**
+ * get already existing instance, make new instance or throw an exception
+ * @param string $instanceName
+ * @param Zend_Db_Adapter $db
+ * @param string $where
+ */
+ public static function getInstance($instanceName, $db = null, $where = null) {
+ if ($instanceName === null)
+ throw new Exception(__METHOD__ . ': expected an instance name, got none');
+
+ // no caching if presumeably volatile data is requested
+ if ($db !== null && $where !== null) {
+ return new Config($instanceName, $db, $where);
+ }
+
+ if (!array_key_exists($instanceName, self::$instances)) {
+ self::$instances[$instanceName] = new Config($instanceName, $db, $where);
+ }
+
+ return self::$instances[$instanceName];
+ }
+
+ /**
+ * magic method that dispatches all unrecognized method calls to the config object
+ *
+ * @param string $param
+ */
+ public function __get($param) {
+ return $this->config->$param;
+ }
+
+ /**
+ * magic method that handles isset inquiries to attributes
+ *
+ * @param string $param
+ */
+ public function __isset($param) {
+ return isset($this->config->$param);
+ }
+
+ /**
+ * magic method that dispatches all unrecognized method calls to the config object
+ *
+ * @param string $param
+ * @param string $value
+ */
+ public function __set($param, $value) {
+ $this->config->$param = $value;
+ }
+
+ /**
+ * get the config object
+ * @return Zend_Config_*
+ */
+ public function getConfig() {
+ return $this->config;
+ }
}
diff --git a/manager/library/config/Config_Db.php b/manager/library/config/Config_Db.php
index 83af68b..6bf0e9c 100644
--- a/manager/library/config/Config_Db.php
+++ b/manager/library/config/Config_Db.php
@@ -36,7 +36,7 @@ require_once 'Zend/Config.php';
*/
class Config_Db extends Zend_Config
{
- /**
+ /**
* String that separates nesting levels of configuration data identifiers
*
* @var string
@@ -94,7 +94,7 @@ class Config_Db extends Zend_Config
* );
*
* @param Zend_Db $dbc
- * @param string $db_table
+ * @param string $db_table
* @param string|null $section
* @param boolean|array $options
* @throws Zend_Config_Exception
@@ -134,7 +134,7 @@ class Config_Db extends Zend_Config
}
$iniArray = $this->_loadIniFile($dbc, $db_table, $section);
- $section = null;
+ $section = null;
if (null === $section) {
// Load entire file
@@ -233,28 +233,28 @@ class Config_Db extends Zend_Config
* @return array
*/
protected function _parse_ini_db($dbc, $db_table, $section) {
- $sql = 'select * from ' . $db_table;
- if ($section !== null) {
- $sql .= ' where ' . $section;
- }
+ $sql = 'select * from ' . $db_table;
+ if ($section !== null) {
+ $sql .= ' where ' . $section;
+ }
- $db_config = $dbc->query($sql);
+ $db_config = $dbc->query($sql);
- $config = array();
+ $config = array();
- while (($row = $db_config->fetch()) !== false) {
- $key = explode('.', $row['config_key']);
- $depth = count($key);
- $ci = &$config;
- for ($cnt = 0; $cnt < $depth; $cnt++) {
- if ($cnt == ($depth - 1))
- $ci[$key[$cnt]] = $row['config_value'];
- elseif (!isset($ci[$key[$cnt]]))
- $ci[$key[$cnt]] = array();
- $ci = &$ci[$key[$cnt]];
- }
- }
- return $config;
+ while (($row = $db_config->fetch()) !== false) {
+ $key = explode('.', $row['config_key']);
+ $depth = count($key);
+ $ci = &$config;
+ for ($cnt = 0; $cnt < $depth; $cnt++) {
+ if ($cnt == ($depth - 1))
+ $ci[$key[$cnt]] = $row['config_value'];
+ elseif (!isset($ci[$key[$cnt]]))
+ $ci[$key[$cnt]] = array();
+ $ci = &$ci[$key[$cnt]];
+ }
+ }
+ return $config;
}
/**
diff --git a/manager/library/config/Config_Writer_Db.php b/manager/library/config/Config_Writer_Db.php
index 132c456..126437f 100644
--- a/manager/library/config/Config_Writer_Db.php
+++ b/manager/library/config/Config_Writer_Db.php
@@ -86,14 +86,14 @@ class Config_Writer_Db extends Zend_Config_Writer
* @return void
*/
public function write($db = null, $config = null, $set = null) {
- $this->_set = $set;
+ $this->_set = $set;
- // this method is specialized for writing back Config objects (which hold config_db objects)
+ // this method is specialized for writing back Config objects (which hold config_db objects)
if ($config !== null) {
- if ($config instanceof Config)
- $this->setConfig($config->getConfig());
+ if ($config instanceof Config)
+ $this->setConfig($config->getConfig());
else {
- $this->setConfig($config);
+ $this->setConfig($config);
}
}
@@ -111,66 +111,66 @@ class Config_Writer_Db extends Zend_Config_Writer
$string = 'delete from ' . $this->_tableName;
if ($this->_set !== null) {
- $string .= ' where ' . $this->_set;
+ $string .= ' where ' . $this->_set;
}
- $sql[] = $string;
+ $sql[] = $string;
$iniString = '';
$extends = $this->_config->getExtends();
$sectionName = $this->_config->getSectionName();
foreach ($this->_config as $key => $data) {
- $sql= array_merge($sql, $this->addEntry($sectionName, $key, $data));
- }
-
- try {
- $db->beginTransaction();
- foreach ($sql as $command) {
- #Log::Log()->debug($command);
- $db->query($command);
- }
- $db->commit();
- } catch (Exception $e) {
- $db->rollBack();
- Log::Log()->err($e);
- throw $e;
- }
- }
-
- /**
- * build key value pairs, key is created by recursively adding section names, delimited by "."
- * @param string $prefix
- * @param string $key
- * @param mixed $data
- */
+ $sql= array_merge($sql, $this->addEntry($sectionName, $key, $data));
+ }
+
+ try {
+ $db->beginTransaction();
+ foreach ($sql as $command) {
+ #Log::Log()->debug($command);
+ $db->query($command);
+ }
+ $db->commit();
+ } catch (Exception $e) {
+ $db->rollBack();
+ Log::Log()->err($e);
+ throw $e;
+ }
+ }
+
+ /**
+ * build key value pairs, key is created by recursively adding section names, delimited by "."
+ * @param string $prefix
+ * @param string $key
+ * @param mixed $data
+ */
protected function addEntry($prefix, $key, $data) {
- $sql = array();
-
- if ($data instanceof Zend_Config) {
- if ($prefix != '')
- $prefix .= '.';
- $prefix .= $key;
- foreach ($data as $k => $v) {
- $sql = array_merge($sql, $this->addEntry($prefix, $k, $v));
- }
- }
- else {
- $string = 'insert into ' . $this->_tableName . ' set ';
- $pkey = $prefix;
- if ($pkey != '')
- $pkey .= '.';
- $pkey .= $key;
- $string .= 'config_key=' . $this->_prepareValue($pkey) . ', ';
- $string .= 'config_value=' . $this->_prepareValue($data);
- if ($this->_set !== null)
- $string .= ', ' . $this->_set;
-
- $sql[] = $string;
- }
-
- return $sql;
- }
+ $sql = array();
+
+ if ($data instanceof Zend_Config) {
+ if ($prefix != '')
+ $prefix .= '.';
+ $prefix .= $key;
+ foreach ($data as $k => $v) {
+ $sql = array_merge($sql, $this->addEntry($prefix, $k, $v));
+ }
+ }
+ else {
+ $string = 'insert into ' . $this->_tableName . ' set ';
+ $pkey = $prefix;
+ if ($pkey != '')
+ $pkey .= '.';
+ $pkey .= $key;
+ $string .= 'config_key=' . $this->_prepareValue($pkey) . ', ';
+ $string .= 'config_value=' . $this->_prepareValue($data);
+ if ($this->_set !== null)
+ $string .= ', ' . $this->_set;
+
+ $sql[] = $string;
+ }
+
+ return $sql;
+ }
/**
* Add a branch to an INI string recursively