00001 <?php
00018 abstract class SConfig
00019 {
00020 # Store our defaults, our options (overrides for defaults),
00021 # and our log of not found options/defaults.
00022 protected static $defaults = array();
00023 protected static $options = array();
00024 protected static $notFound = array();
00025
00026
00027 # Initialize
00028 # ----------------------------------------------
00029
00037 public static function initialize() {
00038 global $COMMON_ROOT, $COMMON_URL;
00039
00040 # Clear out the existing values in prep for reload
00041 SConfig::$defaults = array();
00042 SConfig::$options = array();
00043 SConfig::$notFound = array();
00044
00045 # Include the defaults file found in this directory
00046 self::setDefault('spath.commonURL', $COMMON_URL);
00047 include($COMMON_ROOT . '/config/serverDefaults.php5');
00048 if (file_exists($COMMON_ROOT . '/config/serverLocal.php5'))
00049 include($COMMON_ROOT . '/config/serverLocal.php5');
00050 }
00051
00052
00053 # Defaults
00054 # ----------------------------------------------
00055
00061 public static function setDefault($key, $value) {
00062 SConfig::$defaults[$key] = $value;
00063 return true;
00064 }
00065
00074 public static function getDefault($key) {
00075 if (!isset(SConfig::$defaults[$key])) {
00076 SConfig::addNotFound($key);
00077 return null;
00078 }
00079 return SConfig::$defaults[$key];
00080 }
00081
00090 public static function isDefaultSet($key) {
00091 if (!isset(SConfig::$defaults[$key])) return false;
00092 return true;
00093 }
00094
00095 # Options
00096 # ---------------------------------------------
00097
00107 public static function setOption($key, $value) {
00108 SConfig::$options[$key] = $value;
00109 return true;
00110 }
00111
00120 public static function getOption($key) {
00121 if (!isset(SConfig::$options[$key])){
00122 return SConfig::getDefault($key);
00123 }
00124 return SConfig::$options[$key];
00125 }
00126
00135 public static function isOptionSet($key) {
00136 if (!isset(SConfig::$options[$key])) return SConfig::isDefaultSet($key);
00137 return true;
00138 }
00139
00140
00141 # Log of "not found" access misses
00142 # ---------------------------------------------
00143
00152 protected static function addNotFound($key) {
00153 array_push(SConfig::$notFound, $key);
00154 }
00155
00163 public static function getNotFound() {
00164 return SConfig::$notFound;
00165 }
00166
00167 }
00168 ?>