3 // @title Configuration Component
5 // @updated 2006-05-24 16:22:35
6 // @desc The module for storing and retreiving configuration data
8 include_once('stdexception.php');
11 public static $environment = '';
12 public static $config = array();
14 // instance methods (for accessing)
15 public function __construct() {
16 // make sure that the config data has been loaded
17 if(empty(self
::$config)) self
::load();
19 public function __get($name) {
20 return self
::$config[$name];
22 public function __set($name, $value) {
26 // static methods (for loading)
27 public static function load() {
28 // load cached/serialized configuration
29 self
::$config = self
::load_cache();
31 // check for cache expiration (by updating the originals)
32 if(self
::cache_expired()) {
33 $begin_time = microtime(true);
35 // cache has expired, so update it
36 self
::$config = self
::load_config();
41 $time = microtime(true) - $begin_time;
43 // log that config files were reloaded and cached
44 Debug
::log("Config files were reloaded and cached ({$time}sec)", 'config', 'notice', 'Config');
47 // set the environment static property
48 self
::$environment = self
::$config['environment'];
50 // map convention-modifying configurations
53 // return the configuration
57 public static function load_cache() {
58 return unserialize(@file_get_contents
(Conventions
::config_cache_file()));
61 public static function load_config() {
62 // get the YAML generic configurations and database configurations
63 $config = YAML
::load(Conventions
::config_file('config'));
64 $config['database'] = YAML
::load(Conventions
::config_file('database'));
66 // disabled because the Routes file is PHP instead of YAML
67 // $config['routes'] = YAML::load(Conventions::config_file('routes'));
72 public static function save_cache() {
73 self
::$config['checksum'] = self
::config_checksum();
74 $cache = serialize(self
::$config);
75 @file_put_contents
(Conventions
::config_cache_file(), $cache);
78 public static function cache_expired() {
79 if(self
::$config['checksum'] != self
::config_checksum()) {
88 public static function config_checksum() {
90 @file_get_contents
(Conventions
::config_file('config'))
91 . @file_get_contents
(Conventions
::config_file('database'))
92 // disabled because the Routes file is PHP instead of YAML
93 // . @file_get_contents(Conventions::config_file('routes'))
97 // map convention-modifying configs
98 public static function map_config() {
99 // map directories (may add new ones, which is OK)
100 foreach(self
::$config['directories'] as $convention=>$dir) {
101 Conventions
::$directories[$convention] = $dir;