This repository has been archived on 2024-06-26. You can view files and clone it, but cannot push or open issues or pull requests.
sakura/_sakura/components/Configuration.php

77 lines
1.8 KiB
PHP
Raw Normal View History

<?php
/*
* Configuration Management
*/
namespace Flashii;
class Configuration {
public static $_LCNF;
public static $_DCNF;
// Constructor
public static function init($local) {
2015-03-08 06:11:57 +00:00
// Store $local in $_LCNF
if(is_array($local))
self::$_LCNF = $local;
else
die('<h1>Failed to initialise configuration.</h1>');
2015-03-08 06:11:57 +00:00
}
// Initialise Database configuration values.
// Different from __construct as that is called before the database connection is initially
// established
public static function initDB() {
2015-03-08 06:11:57 +00:00
$_DATA = Database::fetch('config', true);
$_DBCN = array();
foreach($_DATA as $_CONF)
$_DBCN[$_CONF[0]] = $_CONF[1];
self::$_DCNF = $_DBCN;
2015-03-08 06:11:57 +00:00
}
// Get values from the configuration on the file system
public static function getLocalConfig($key, $subkey = null) {
2015-03-08 06:11:57 +00:00
if(array_key_exists($key, self::$_LCNF)) {
if($subkey)
return self::$_LCNF[$key][$subkey];
else
return self::$_LCNF[$key];
} else
return null;
2015-03-08 06:11:57 +00:00
}
// Dynamically set local configuration values, does not update the configuration file
public static function setLocalConfig($key, $subkey, $value) {
2015-03-08 06:11:57 +00:00
if($subkey) {
if(!isset(self::$_LCNF[$key])) {
self::$_LCNF[$key] = array();
}
self::$_LCNF[$key][$subkey] = $value;
} else {
self::$_LCNF[$key] = $value;
}
2015-03-08 06:11:57 +00:00
}
// Get values from the configuration in the database
public static function getConfig($key) {
2015-03-08 06:11:57 +00:00
if(array_key_exists($key, self::$_DCNF))
2015-03-08 06:11:57 +00:00
return self::$_DCNF[$key];
else
return null;
2015-03-08 06:11:57 +00:00
}
}