Setting up my convoluted web parsing structure... in short:
[glcas.git] / libglcas / config.php
diff --git a/libglcas/config.php b/libglcas/config.php
new file mode 100644 (file)
index 0000000..634b69a
--- /dev/null
@@ -0,0 +1,69 @@
+<?php
+
+class GLCASConfig {
+       
+       function __construct()
+       {
+               $this->configPath = "";
+               $this->config = "";
+       }
+       
+       function loadConfig($configpath)
+       {
+               error_log("loadConfig $configpath");
+               $this->configPath = $configpath;
+               $flt = file_get_contents($configpath);
+               $this->config = unserialize(base64_decode($flt));
+               
+               
+       }
+       
+       function setConfigVar($var, $value)
+       {
+               if(is_array($this->config)) {
+                       foreach($this->config as $vkey => $val) {
+                               if($vkey == "$var") {
+                                       error_log("reset config of $var to $value");
+                                       $this->config[$var] = $value;
+                                       return true;
+                               }
+                       }
+               } else error_log("config isnt array");
+               
+               // otherwise, set it
+               error_log("set config of $var to $value");
+               $this->config[$var] = $value;
+       }
+       
+       function delConfigVar($var)
+       {
+               if(is_array($this->config)) {
+                       foreach($this->config as $vkey => $val) {
+                               if($vkey == "$var") {
+                                       error_log("remove config of $var to $value");
+                                       unset($this->config[$var]);
+                                       return true;
+                               }
+                       }
+               } else error_log("config isnt array");
+       }
+       
+       function saveConfig()
+       {
+               file_put_contents($this->configPath, base64_encode(serialize($this->config)));
+       }
+       
+       function debug()
+       {
+               echo "<pre>";
+               echo "path: ".$this->configPath."\n";
+               print_r($this->config);
+               echo "</pre>";
+       }
+       
+       private $configPath;
+       private $config;
+       
+}
+
+?>
\ No newline at end of file