summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksander Machniak <machniak@kolabsys.com>2012-05-11 11:35:28 +0200
committerAleksander Machniak <machniak@kolabsys.com>2012-05-11 11:35:28 +0200
commit4ef95461d4cb3c4bdf045ab01d9820c039e19060 (patch)
treeef22b93b59d6b016fd85e64a83c9f3abbed37c92
parent92aeb73fb6e7788a0c9219e9a3aa28e0c294163c (diff)
downloadwebadmin-4ef95461d4cb3c4bdf045ab01d9820c039e19060.tar.gz
Support boolean values in config file
-rw-r--r--lib/Conf.php26
-rw-r--r--lib/kolab_client_api.php16
2 files changed, 31 insertions, 11 deletions
diff --git a/lib/Conf.php b/lib/Conf.php
index e8a9a02..e91110c 100644
--- a/lib/Conf.php
+++ b/lib/Conf.php
@@ -30,6 +30,11 @@ class Conf {
const CONFIG_FILE = '/etc/kolab/kolab.conf';
+ const STRING = 0;
+ const BOOL = 1;
+ const INT = 2;
+ const FLOAT = 3;
+
/**
* This implements the 'singleton' design pattern
*
@@ -55,9 +60,24 @@ class Conf {
}
- public function get($key1, $key2 = NULL)
+ public function get($key1, $key2 = null, $type = null)
{
- return $this->expand($this->get_raw($key1, $key2));
+ $value = $this->expand($this->get_raw($key1, $key2));
+
+ if ($value === null) {
+ return $value;
+ }
+
+ switch ($type) {
+ case self::INT:
+ return intval($value);
+ case self::FLOAT:
+ return floatval($value);
+ case self::BOOL:
+ return (bool) preg_match('/^(true|1|on|enabled|yes)$/i', $value);
+ }
+
+ return (string) $value;
}
public function get_list($key1, $key2 = NULL)
@@ -131,7 +151,7 @@ class Conf {
// error_log("Could not find setting for \$key1: " . $key1 .
// " with \$key2: " . $key2);
- return false;
+ return null;
}
public function expand($str, $custom = FALSE)
diff --git a/lib/kolab_client_api.php b/lib/kolab_client_api.php
index 4159a84..622842a 100644
--- a/lib/kolab_client_api.php
+++ b/lib/kolab_client_api.php
@@ -64,16 +64,16 @@ class kolab_client_api
// Configure connection options
$config = Conf::get_instance();
$options = array(
- 'ssl_verify_peer',
- 'ssl_verify_host',
- 'ssl_cafile',
- 'ssl_capath',
- 'ssl_local_cert',
- 'ssl_passphrase',
+ 'ssl_verify_peer' => Conf::BOOL,
+ 'ssl_verify_host' => Conf::BOOL,
+ 'ssl_cafile' => Conf::STRING,
+ 'ssl_capath' => Conf::STRING,
+ 'ssl_local_cert' => Conf::STRING,
+ 'ssl_passphrase' => Conf::STRING,
);
- foreach ($options as $optname) {
- if (($optvalue = $config->get('kolab_wap', $optname)) !== null) {
+ foreach ($options as $optname => $opttype) {
+ if (($optvalue = $config->get('kolab_wap', $optname, $opttype)) !== null) {
try {
$this->request->setConfig($optname, $optvalue);
}