summaryrefslogtreecommitdiff
path: root/lib/Kolab/FreeBusy/Config.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Kolab/FreeBusy/Config.php')
-rw-r--r--lib/Kolab/FreeBusy/Config.php60
1 files changed, 45 insertions, 15 deletions
diff --git a/lib/Kolab/FreeBusy/Config.php b/lib/Kolab/FreeBusy/Config.php
index c0101e9..d80ef7f 100644
--- a/lib/Kolab/FreeBusy/Config.php
+++ b/lib/Kolab/FreeBusy/Config.php
@@ -1,61 +1,91 @@
<?php
-namespace Kolab;
+namespace Kolab\FreeBusy;
/**
* Wrapper class for service configuration
*/
-class FBConfig
+class Config
{
private static $instance;
+ private $basedir = '.';
private $data = array();
private $valid = false;
/**
* Singelton getter
+ *
+ * @param string Path to load config from
*/
public static function getInstance($dir = null)
{
if (!isset(self::$instance)) {
- self::$instance = new FBConfig($dir);
+ self::$instance = new Config($dir);
}
- if ($dir && !self::$instance->valid)
- self::$instance->_load($dir);
+ if ($dir && !self::$instance->valid) {
+ self::$instance->load($configdir . '/config.ini');
+ }
return self::$instance;
}
/**
* Default constructor
- *
- * @param string Path to load config from
*/
function __construct($configdir = null)
{
if ($configdir) {
- $this->_load($configdir);
+ $this->basedir = $configdir;
+ $this->load($configdir . '/config.ini');
}
}
-
- private function _load($configdir)
+
+ /**
+ * Load config from the given .ini file
+ */
+ private function load($inifile)
{
- if ($raw = @parse_ini_file($configdir . '/config.ini', true)) {
+ if ($raw = parse_ini_file($inifile, true)) {
foreach ($raw as $section => $values) {
// check for known sections
if (in_array($section, array('httpauth','trustednetworks','log'))) {
- $this->data[$section] = $values;
+ $config[$section] = $values;
}
- else if (isset($values['fbsource'])){
- $this->data['directories'][] = $values;
+ else if (strpos($section, 'directory') === 0 || isset($values['fbsource'])){
+ $config['directories'][] = $values;
}
}
+ $this->register($config);
$this->valid = !empty($this->data['directories']);
}
else {
- trigger_error("Failed to parse configuration from $config_dir/config.ini", E_USER_ERROR);
+ trigger_error("Failed to parse configuration from $inifile", E_USER_ERROR);
+ }
+ }
+
+ /**
+ * Dump the hierarchical structure of config options into a flat list with keys delimited by dots
+ */
+ private function register($config, $prefix = '')
+ {
+ if (empty($prefix)) {
+ $this->data = array_replace_recursive($this->data, $config);
+ }
+ else if (is_array($config)) {
+ $pkey = rtrim($prefix, '.');
+ $this->data[$pkey] = is_array($this->data[$pkey]) ? array_replace_recursive((array)$this->data[$pkey], $config) : $config;
+ }
+
+ foreach ((array)$config as $key => $val) {
+ if (is_array($val)) {
+ $this->register($val, "$prefix$key.");
+ }
+ else {
+ $this->data[$prefix.$key] = $val;
+ }
}
}