lib/Kolab

Thomas Brüderli bruederli at kolabsys.com
Thu Jan 17 15:15:37 CET 2013


 lib/Kolab/FreeBusy/Config.php |   27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

New commits:
commit 2d8591089c85e85da1e0f0c3f719afff4949e1d5
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date:   Thu Jan 17 15:15:28 2013 +0100

    Support references in config propertes (e.g. '%(foo.bar)')

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]];
 	}
 
 	/**





More information about the commits mailing list