Config.php
1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
class Config
{
private static $system = array();
private static $fileName = '';
private static $change_flag = false;
private static $obj;
private function __construct(){}
private function __clone(){}
public static function getInstance()
{
if(!self::$obj instanceof self)
{
self::$fileName = APP_CODE_ROOT.'config/system.php';
self::$system = require(self::$fileName);
if(!is_array(self::$system)) self::$system = array();
self::$obj = new self();
}
return self::$obj;
}
public function get($key)
{
if(isset(self::$system[$key])) return self::$system[$key];
else return null;
}
public function set($key,$value)
{
if(!isset(self::$system[$key]) || self::$system[$key] != $value)
{
self::$change_flag = true;
self::$system[$key] = $value;
}
}
public function del($key)
{
if(isset(self::$system[$key])) unset(self::$system[$key]);
}
public function __destruct()
{
if(self::$change_flag)File::putContents(self::$fileName,'<?php return '.var_export(self::$system,true).';');
}
}