Setting up my convoluted web parsing structure... in short:
[glcas.git] / libglcas / config.php
1 <?php
2
3 class GLCASConfig {
4         
5         function __construct()
6         {
7                 $this->configPath = "";
8                 $this->config = "";
9         }
10         
11         function loadConfig($configpath)
12         {
13                 error_log("loadConfig $configpath");
14                 $this->configPath = $configpath;
15                 $flt = file_get_contents($configpath);
16                 $this->config = unserialize(base64_decode($flt));
17                 
18                 
19         }
20         
21         function setConfigVar($var, $value)
22         {
23                 if(is_array($this->config)) {
24                         foreach($this->config as $vkey => $val) {
25                                 if($vkey == "$var") {
26                                         error_log("reset config of $var to $value");
27                                         $this->config[$var] = $value;
28                                         return true;
29                                 }
30                         }
31                 } else error_log("config isnt array");
32                 
33                 // otherwise, set it
34                 error_log("set config of $var to $value");
35                 $this->config[$var] = $value;
36         }
37         
38         function delConfigVar($var)
39         {
40                 if(is_array($this->config)) {
41                         foreach($this->config as $vkey => $val) {
42                                 if($vkey == "$var") {
43                                         error_log("remove config of $var to $value");
44                                         unset($this->config[$var]);
45                                         return true;
46                                 }
47                         }
48                 } else error_log("config isnt array");
49         }
50         
51         function saveConfig()
52         {
53                 file_put_contents($this->configPath, base64_encode(serialize($this->config)));
54         }
55         
56         function debug()
57         {
58                 echo "<pre>";
59                 echo "path: ".$this->configPath."\n";
60                 print_r($this->config);
61                 echo "</pre>";
62         }
63         
64         private $configPath;
65         private $config;
66         
67 }
68
69 ?>