1: <?php
2: /**
3: * WsConfig
4: * Sets or fetch config variables. Good practice is to define all default config
5: * variables in 'protected/config/config.php' file.
6: *
7: * Example usage:
8: *
9: * <code>
10: * // get database driver name
11: * $cs = WsConfig::get('db_driver');
12: *
13: * // set database host name to localhost
14: * WsConfig::set('db_host', 'localhost');
15: * </code>
16: *
17: */
18: class WsConfig
19: {
20: private static $vars = array();
21:
22: /**
23: * Sets global configuration variable.
24: *
25: * @param string $_name Variable name
26: * @param string $_value Variable value
27: * @return boolean True on success
28: */
29: public static function set($_name, $_value)
30: {
31: self::$vars[$_name] = $_value;
32: return true;
33: }
34:
35:
36: /**
37: * Fetch global configuration variable.
38: *
39: * @param string $_name Variable name
40: * @return string Value of variable
41: *
42: */
43: public static function get($_name)
44: {
45: if(array_key_exists($_name, self::$vars)) {
46: return self::$vars[$_name];
47: } else {
48: return '';
49: }
50: }
51:
52:
53: /**
54: * Check if config variable exists
55: *
56: * @param string $_name Variable name
57: * @return boolean True or False
58: *
59: */
60: public static function exists($_name)
61: {
62: if(array_key_exists($_name, self::$vars)) {
63: return true;
64: }
65:
66: return false;
67: }
68: }
69: