source: trunk/Packages/Common/Config.php

Last change on this file was 8, checked in by chronos, 19 months ago
  • Modified: Updated Common package.
  • Modified: Form types made as separate FormManager package.
  • Fixed: PHP 8.1 support.
File size: 1.1 KB
Line 
1<?php
2
3class Config
4{
5 public array $Data;
6
7 function __construct()
8 {
9 $this->Data = array();
10 }
11
12 function ReadValue(string $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(string $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(string $FileName): void
37 {
38 $ConfigData = array();
39 include $FileName;
40 foreach ($this->Data as $Index => $Item)
41 {
42 if (array_key_exists($Index, $ConfigData))
43 $this->Data[$Index] = $ConfigData[$Index];
44 }
45 }
46
47 function SaveToFile(string $FileName): void
48 {
49 file_put_contents($FileName, "<?php \n\n\$ConfigData = ".var_export($this->Data, true).";\n");
50 }
51
52 function GetAsArray(): array
53 {
54 return $this->Data;
55 }
56}
Note: See TracBrowser for help on using the repository browser.