pickles/classes/Config.php
2008-09-17 01:57:01 +00:00

58 lines
1.1 KiB
PHP
Executable file

<?php
class Config extends Singleton {
private static $instance;
public $timestamp = null;
private function __construct() { }
public static function getInstance() {
$session = Session::getInstance();
$class = __CLASS__;
if (isset($session->$class)) {
self::$instance = Singleton::thaw($class);
}
else if (!self::$instance instanceof $class) {
self::$instance = new $class();
}
return self::$instance;
}
public function load($site) {
if (!isset($this->file) || filemtime($this->file) > $this->timestamp) {
$file = PICKLES_PATH . 'config/' . $site . '.xml';
if (file_exists($file)) {
$this->file = $file;
$config_array = ArrayUtils::object2array(simplexml_load_file($file));
if (is_array($config_array)) {
foreach ($config_array as $variable => $value) {
if ($value == 'true' || $value == array()) {
$value = (bool) $value;
}
$this->$variable = $value == array() ? (bool) $value : $value;
}
}
$this->freeze();
return true;
}
else {
Error::addError('Unable to load the configuration file');
return false;
}
}
}
}
?>