summaryrefslogtreecommitdiffstats
path: root/lib/Conf.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Conf.php')
-rw-r--r--lib/Conf.php178
1 files changed, 90 insertions, 88 deletions
diff --git a/lib/Conf.php b/lib/Conf.php
index af3769b..2fbe9d1 100644
--- a/lib/Conf.php
+++ b/lib/Conf.php
@@ -1,116 +1,118 @@
<?php
- class Conf {
- static private $instance;
-
- /**
- * This implements the 'singleton' design pattern
- *
- * @return Conf The one and only instance
- */
- static function get_instance()
- {
- if (!self::$instance) {
- self::$instance = new Conf();
- }
-
- return self::$instance;
+class Conf {
+ static private $instance;
+
+ /**
+ * This implements the 'singleton' design pattern
+ *
+ * @return Conf The one and only instance
+ */
+ static function get_instance()
+ {
+ if (!self::$instance) {
+ self::$instance = new Conf();
}
- public function __construct()
- {
- // Do some magic configuration loading here.
- if (file_exists('/etc/kolab/kolab.conf'))
- {
- $_ini_raw = file('/etc/kolab/kolab.conf');
+ return self::$instance;
+ }
- $this->_conf = Array();
+ public function __construct()
+ {
+ // Do some magic configuration loading here.
+ if (!file_exists('/etc/kolab/kolab.conf')) {
+ return;
+ }
- foreach ($_ini_raw as $_line) {
- if (preg_match('/^\[([a-z0-9-_\.]+)\]/', $_line, $matches)) {
- $_cur_section = $matches[1];
- $this->_conf[$_cur_section] = Array();
- unset($_cur_key);
- }
+ $_ini_raw = file('/etc/kolab/kolab.conf');
- if (preg_match('/^;/', $_line, $matches)) {
- }
+ $this->_conf = array();
- if (preg_match('/^([a-z0-9\.-_]+)\s*=\s*(.*)/', $_line, $matches)) {
- if (isset($_cur_section) && !empty($_cur_section)) {
- $_cur_key = $matches[1];
- $this->_conf[$_cur_section][$matches[1]] = isset($matches[2]) ? $matches[2] : '';
+ foreach ($_ini_raw as $_line) {
+ if (preg_match('/^\[([a-z0-9-_\.]+)\]/', $_line, $matches)) {
+ $_cur_section = $matches[1];
+ $this->_conf[$_cur_section] = array();
+ unset($_cur_key);
+ }
- }
- }
+ if (preg_match('/^;/', $_line, $matches)) {
+ }
- if (preg_match('/^\s+(.*)$/', $_line, $matches)) {
- if (isset($_cur_key) && !empty($_cur_key)) {
- $this->_conf[$_cur_section][$_cur_key] .= $matches[1];
- }
- }
+ if (preg_match('/^([a-z0-9\.-_]+)\s*=\s*(.*)/', $_line, $matches)) {
+ if (isset($_cur_section) && !empty($_cur_section)) {
+ $_cur_key = $matches[1];
+ $this->_conf[$_cur_section][$matches[1]] = isset($matches[2]) ? $matches[2] : '';
}
}
- }
- public function get($key1, $key2 = NULL) {
- return $this->expand($this->get_raw($key1, $key2));
+ if (preg_match('/^\s+(.*)$/', $_line, $matches)) {
+ if (isset($_cur_key) && !empty($_cur_key)) {
+ $this->_conf[$_cur_section][$_cur_key] .= $matches[1];
+ }
+ }
}
+ }
- public function get_raw($key1, $key2 = NULL) {
- if (isset($this->_conf[$key1])) {
- if ($key2) {
- if (isset($this->_conf[$key1][$key2])) {
- return $this->_conf[$key1][$key2];
- } elseif (isset($this->_conf['kolab'][$key2])) {
- return $this->_conf['kolab'][$key2];
- }
- } else {
- return $this->_conf[$key1];
+ public function get($key1, $key2 = NULL)
+ {
+ return $this->expand($this->get_raw($key1, $key2));
+ }
+
+ public function get_raw($key1, $key2 = NULL)
+ {
+ if (isset($this->_conf[$key1])) {
+ if ($key2) {
+ if (isset($this->_conf[$key1][$key2])) {
+ return $this->_conf[$key1][$key2];
+ }
+ else if (isset($this->_conf['kolab'][$key2])) {
+ return $this->_conf['kolab'][$key2];
}
}
-
- // Simple (global) settings may be obtained by calling the key and omitting
- // the section. This goes for sections 'kolab', and whatever is the equivalent
- // of 'kolab', 'auth_mechanism'.
-# echo "<pre>";
-# print_r($this->_conf);
-# echo "</pre>";
-
- if (isset($this->_conf['kolab'][$key1])) {
- return $this->_conf['kolab'][$key1];
- } elseif (isset($this->_conf[$this->_conf['kolab']['auth_mechanism']][$key1])) {
- return $this->_conf[$this->_conf['kolab']['auth_mechanism']][$key1];
+ else {
+ return $this->_conf[$key1];
}
-
}
- public function expand($str, $custom = FALSE) {
- if (preg_match_all('/%\((?P<variable>\w+)\)s/', $str, $matches)) {
- if (isset($matches['variable']) && !empty($matches['variable'])) {
- if (is_array($matches['variable'])) {
- foreach ($matches['variable'] as $key => $value) {
- if (is_array($custom) && array_key_exists($value, $custom)) {
- $str = str_replace("%(" . $value . ")s", $custom[$value], $str);
- }
+ // Simple (global) settings may be obtained by calling the key and omitting
+ // the section. This goes for sections 'kolab', and whatever is the equivalent
+ // of 'kolab', 'auth_mechanism'.
+// echo "<pre>";
+// print_r($this->_conf);
+// echo "</pre>";
- $str = str_replace("%(" . $value . ")s", $this->get($value), $str);
- }
+ if (isset($this->_conf['kolab'][$key1])) {
+ return $this->_conf['kolab'][$key1];
+ }
+ else if (isset($this->_conf[$this->_conf['kolab']['auth_mechanism']][$key1])) {
+ return $this->_conf[$this->_conf['kolab']['auth_mechanism']][$key1];
+ }
+ }
- return $str;
+ public function expand($str, $custom = FALSE)
+ {
+ if (preg_match_all('/%\((?P<variable>\w+)\)s/', $str, $matches)) {
+ if (isset($matches['variable']) && !empty($matches['variable'])) {
+ if (is_array($matches['variable'])) {
+ foreach ($matches['variable'] as $key => $value) {
+ if (is_array($custom) && array_key_exists($value, $custom)) {
+ $str = str_replace("%(" . $value . ")s", $custom[$value], $str);
+ }
- } else {
- return str_replace("%(" . $matches['variable'] . ")s", $this->get($matches['variable']), $str);
+ $str = str_replace("%(" . $value . ")s", $this->get($value), $str);
}
- }
-
- return $str;
- } else {
- return $str;
+ return $str;
+ }
+ else {
+ return str_replace("%(" . $matches['variable'] . ")s", $this->get($matches['variable']), $str);
+ }
}
- }
+ return $str;
+ }
+ else {
+ return $str;
+ }
}
-
-?>
+}