source: web/Packages/Common/Config.php

Last change on this file was 17, checked in by chronos, 8 years ago
  • Modified: Old database class replaced by newer from Common package to fix compatibility with PHP7.
File size: 1.0 KB
Line 
1<?php
2
3class Config
4{
5 var $Data;
6
7 function __construct()
8 {
9 $this->Data = array();
10 }
11
12 function ReadValue($Name)
13 {
14 if(!is_array($Name)) $Name = explode('/', $Name);
15 $Last = array_pop($Name);
16 $Data = &$this->Data;
17 foreach($Name as $Item)
18 {
19 $Data = &$Data[$Item];
20 }
21 return($Data[$Last]);
22 }
23
24 function WriteValue($Name, $Value)
25 {
26 if(!is_array($Name)) $Name = explode('/', $Name);
27 $Last = array_pop($Name);
28 $Data = &$this->Data;
29 foreach($Name as $Item)
30 {
31 $Data = &$Data[$Item];
32 }
33 $Data[$Item] = $Value;
34 }
35
36 function LoadFromFile($FileName)
37 {
38 $ConfigData = array();
39 include $FileName;
40 foreach($this->Data as $Index => $Item)
41 {
42 if(array_key_exits($Index, $ConfigData))
43 $this->Data[$Index] = $ConfigData[$Index];
44 }
45 }
46
47 function SaveToFile($FileName)
48 {
49 file_put_contents($FileName, "<?php \n\n\$ConfigData = ".var_export($this->Data, true).";\n");
50 }
51
52 function GetAsArray()
53 {
54 return($this->Data);
55 }
56}
Note: See TracBrowser for help on using the repository browser.