summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Bruederli <bruederli@kolabsys.com>2013-01-17 14:15:28 (GMT)
committerThomas Bruederli <bruederli@kolabsys.com>2013-01-17 14:15:28 (GMT)
commit2d8591089c85e85da1e0f0c3f719afff4949e1d5 (patch)
tree1f5e2b1274628d165c6499ce80a1873b458885dc
parentae5792a9e1ba9576eee49b515119b80616be9567 (diff)
downloadkolab-freebusy-2d8591089c85e85da1e0f0c3f719afff4949e1d5.tar.gz
Support references in config propertes (e.g. '%(foo.bar)')
-rw-r--r--lib/Kolab/FreeBusy/Config.php27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/Kolab/FreeBusy/Config.php b/lib/Kolab/FreeBusy/Config.php
index 205a438..7b2ff5f 100644
--- a/lib/Kolab/FreeBusy/Config.php
+++ b/lib/Kolab/FreeBusy/Config.php
@@ -59,6 +59,9 @@ class Config
$key = strlen($sect) ? $sect : count($config['directories']);
$config['directories'][$key] = $values;
}
+ else if (!empty($values) && is_array($values)) {
+ $config[$section] = $values;
+ }
}
$this->register($config);
@@ -74,6 +77,7 @@ class Config
*/
private function register($config, $prefix = '')
{
+ // merge the new config values over existing data
if (empty($prefix)) {
$this->data = array_replace_recursive($this->data, $config);
}
@@ -90,6 +94,29 @@ class Config
$this->data[$prefix.$key] = $val;
}
}
+
+ // resolve references in config options (e.g. %(foo.bar))
+ if (empty($prefix)) {
+ array_walk_recursive($this->data, array($this, 'resolve_reference'));
+ }
+ }
+
+ /**
+ * Callback to resolve references in the given config option value
+ */
+ private function resolve_reference(&$value, $key)
+ {
+ if (is_string($value)) {
+ $value = preg_replace_callback('/%[({]([\w.]+)[})]/i', array($this, 'replace_reference'), $value);
+ }
+ }
+
+ /**
+ * Callback function to replace the given reference with the read config value
+ */
+ private function replace_reference($m)
+ {
+ return $this->data[$m[1]];
}
/**