pickles/classes/Config.php
Josh Sherman ebe214d8e4 Made some changes to accomodate a new server.
git-svn-id: http://svn.cleancode.org/svn/pickles@49 4d10bc64-7434-11dc-a737-d2d0f8310089
2008-09-18 04:38:02 +00:00

59 lines
1.2 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) {
// @todo getting warnings on the filemtime
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;
}
}
}
}
?>