1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Loads and reads config file. |
4
|
|
|
*/ |
5
|
|
|
class Xhgui_Config |
6
|
|
|
{ |
7
|
|
|
private static $_config = array(); |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Load a config file, it will replace |
11
|
|
|
* all the currently loaded configuration. |
12
|
|
|
* |
13
|
|
|
* @param string $file |
14
|
|
|
* @return void |
15
|
|
|
*/ |
16
|
|
|
public static function load($file) |
17
|
|
|
{ |
18
|
|
|
$config = include($file); |
19
|
|
|
self::$_config = array_merge(self::$_config, $config); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Read a config value. |
24
|
|
|
* |
25
|
|
|
* @param string $name The name of the config variable |
26
|
|
|
* @return The value or null. |
27
|
|
|
*/ |
28
|
|
|
public static function read($name) |
29
|
|
|
{ |
30
|
|
|
if (isset(self::$_config[$name])) { |
31
|
|
|
return self::$_config[$name]; |
32
|
|
|
} |
33
|
|
|
return null; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Get all the configuration options. |
38
|
|
|
* |
39
|
|
|
* @return array |
40
|
|
|
*/ |
41
|
|
|
public static function all() |
42
|
|
|
{ |
43
|
|
|
return self::$_config; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Write a config value. |
48
|
|
|
* |
49
|
|
|
* @param string $name The name of the config variable |
50
|
|
|
* @param mixed $value The value of the config variable |
51
|
|
|
* @return void |
52
|
|
|
*/ |
53
|
|
|
public static function write($name, $value) |
54
|
|
|
{ |
55
|
|
|
self::$_config[$name] = $value; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Clear out the data stored in the config class. |
60
|
|
|
* |
61
|
|
|
* @return void |
62
|
|
|
*/ |
63
|
|
|
public static function clear() |
64
|
|
|
{ |
65
|
|
|
self::$_config = array(); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Called during profiler initialization |
70
|
|
|
* |
71
|
|
|
* Allows arbitrary conditions to be added configuring how |
72
|
|
|
* Xhgui profiles runs. |
73
|
|
|
* |
74
|
|
|
* @return boolean |
75
|
|
|
*/ |
76
|
|
|
public static function shouldRun() |
77
|
|
|
{ |
78
|
|
|
$callback = self::read('profiler.enable'); |
79
|
|
|
if (!is_callable($callback)) { |
80
|
|
|
return false; |
81
|
|
|
} |
82
|
|
|
return (bool)$callback(); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
} |
86
|
|
|
|