-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.php
75 lines (60 loc) · 1.55 KB
/
config.php
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
class config {
private $file = '';
private $config = false;
public function load($file) {
global $dir;
$this->file = $file;
$path = 'configs';
$type = 'json';
$include = $dir . '/' . $path . '/' . $file . '.' . $type;
if (file_exists($include)) {
$this->config = json_decode(file_get_contents($include), true);
return $this;
}
$type = 'php';
$include = $dir . '/' . $path . '/' . $file . '.' . $type;
if (file_exists($include)) {
$this->config = include $include;
return $this;
}
}
public function get($section = '') {
if (!empty($section) and !empty($this->config[$section])) {
return $this->config[$section];
} else {
return $this->config;
}
}
public function set($data, $section = '', $file = '') {
if (!empty($section) and !empty($this->config[$section])) {
$this->config[$section] = $data;
} else {
$this->config = $data;
}
return $this->save($file);
}
public function save($file = '') {
global $dir;
if (empty($file)) {
$file = $this->file;
}
$path = 'configs';
$type = 'json';
$include = $dir . '/' . $path . '/' . $file . '.' . $type;
return file_put_contents($include, json_encode($this->config));
}
public function config($file = '') {
if (!empty($file)) {
$this->load($file);
}
}
public static function factory($file = '', $section = '', $data = array()) {
$config = new config($file);
if (!empty($data)) {
$config->set($data, $section, $file);
}
return $config->get($section);
}
}
?>