Code

Added a first Idea of the config registry
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 3 May 2010 13:51:58 +0000 (13:51 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 3 May 2010 13:51:58 +0000 (13:51 +0000)
- Not even nearly finished...

git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@18027 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-core/include/class_config.inc
gosa-core/include/class_configRegistry.inc [new file with mode: 0644]

index 07e9152569fd458c8ef48392957ae27fa9ac4d49..741207e2eb06e24e31c6cfbf5db527cd0360921e 100644 (file)
@@ -64,6 +64,8 @@ class config  {
   var $filename = "";
   var $last_modified = 0;
 
+  public $configRegistry = NULL;
+
   /*! \brief Class constructor of the config class
    *  
    *  \param string 'filename' path to the configuration file
@@ -82,6 +84,9 @@ class config  {
     if ($filename != ""){
       $this->parse($filename);
     }
+
+    // Load configuration registry
+    $this->configRegistry = new configRegistry();
   }
 
 
@@ -1070,7 +1075,13 @@ class config  {
    *
    *
    */
-  function get_cfg_value($name, $default= "") {
+  function get_cfg_value($name, $default= "") 
+  {
+      if($this->configRegistry->propertyExists($name)){
+          return($this->configRegistry->getPropertyValue($name));
+      }
+
+
     $name= strtoupper($name);
 
     /* Check if we have a current value for $name */
diff --git a/gosa-core/include/class_configRegistry.inc b/gosa-core/include/class_configRegistry.inc
new file mode 100644 (file)
index 0000000..70a3fc6
--- /dev/null
@@ -0,0 +1,95 @@
+<?php
+
+class configRegistry{
+
+    private $properties = array();
+
+    function __construct(){
+        $this->reload();
+    }
+
+    function reload()
+    {
+        global $class_mapping;
+        foreach ($class_mapping as $cname => $path){
+            $cmethods = get_class_methods($cname);
+            if (is_array($cmethods) && in_array_ics('plInfo',$cmethods)){
+                $def = call_user_func(array($cname, 'plInfo'));;
+                if(isset($def['plProperties'])){
+                    foreach($def['plProperties'] as $property){
+                        $this->register(
+                                $property['name'],
+                                $property['type'],
+                                $property['default'],
+                                $property['description'],
+                                $property['check'],
+                                $property['migrate'],
+                                $property['mandatory']);
+                    }
+                }
+            }
+        }
+    }
+
+    function register($name,$type,$default,$description,$check,$migrate,$mandatory)
+    {
+        $this->properties[$name] = new gosaProperty($name,$type,$default,$description,$check,$migrate,$mandatory);
+    }
+
+    function propertyExists($name)
+    {
+        return(isset($this->properties[$name]));
+    }
+
+    function getProperty($name)
+    {
+        if($this->propertyExists($name)){
+            return($this->properties[$name]);
+        }
+        return(NULL); 
+    }
+
+    function getPropertyValue($name)
+    {   
+        if($this->propertyExists($name)){
+            return($this->properties[$name]->getValue());
+        }
+        return("");
+    }
+}
+
+
+class gosaProperty
+{
+    protected $name = "";
+    protected $type = "string";
+    protected $default = "";
+    protected $description = "";
+    protected $check = "";
+    protected $migrate = "";
+    protected $mandatory = FALSE;
+
+    function __construct($name,$type,$default,$description,$check,$migrate,$mandatory)
+    {
+        $this->name = $name;
+        $this->type = $type;
+        $this->default = $default;
+        $this->description = $description;
+        $this->check = $check;
+        $this->migrate = $migrate;
+        $this->mandatory = $mandatory;
+    }
+
+    function getValue() { return($this->default); }
+    function getName() { return($this->name); }
+    function getType() { return($this->type); }
+    function getDescription() { return($this->description); }
+    function getDefault() { return($this->default); }
+
+    function isValid() 
+    { 
+        return(TRUE);    
+    }
+}
+
+?>