I updated a centos machine from this code... you ripper, it works!
[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 getConfigVar($var)
22         {
23                 if(isset($this->config["$var"])) {
24                         return $this->config["$var"];
25                 } else return false;
26         }
27         
28         function setConfigVar($var, $value)
29         {
30                 if(is_array($this->config)) {
31                         foreach($this->config as $vkey => $val) {
32                                 if($vkey == "$var") {
33                                         error_log("reset config of $var to $value");
34                                         $this->config[$var] = $value;
35                                         return true;
36                                 }
37                         }
38                 } else error_log("config isnt array");
39                 
40                 // otherwise, set it
41                 error_log("set config of $var to $value");
42                 $this->config[$var] = $value;
43
44         }
45         
46         function delConfigVar($var)
47         {
48                 if(is_array($this->config)) {
49                         foreach($this->config as $vkey => $val) {
50                                 if($vkey == "$var") {
51                                         error_log("remove config of $var to $value");
52                                         unset($this->config[$var]);
53                                         return true;
54                                 }
55                         }
56                 } else error_log("config isnt array");
57         }
58         
59         function saveConfig()
60         {
61                 file_put_contents($this->configPath, base64_encode(serialize($this->config)));
62         }
63         
64         function debug()
65         {
66                 echo "<pre>";
67                 echo "path: ".$this->configPath."\n";
68                 print_r($this->config);
69                 echo "</pre>";
70         }
71         
72         private $configPath;
73         private $config;
74         
75 }
76
77 ?>