lib/Conf.php lib/kolab_client_api.php

Aleksander Machniak machniak at kolabsys.com
Fri May 11 11:36:06 CEST 2012


 lib/Conf.php             |   26 +++++++++++++++++++++++---
 lib/kolab_client_api.php |   16 ++++++++--------
 2 files changed, 31 insertions(+), 11 deletions(-)

New commits:
commit 4ef95461d4cb3c4bdf045ab01d9820c039e19060
Author: Aleksander Machniak <machniak at kolabsys.com>
Date:   Fri May 11 11:35:28 2012 +0200

    Support boolean values in config file

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);
                 }





More information about the commits mailing list