Created
July 11, 2010 12:23
-
-
Save mcgivrer/471512 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Configuration file: retrieve config.ini file (set your own path) | |
* and load it into an array. use the <code>__config(group,key)</code> to | |
* retrieve value from config.ini file. | |
* @author Frédéric Delorme<frederic.delorme@gmai.com> | |
* @version 11/07/2010 | |
*/ | |
class Config{ | |
static $_instance = null; | |
static $_parameters = null; | |
public function Config(){ | |
self::$_parameters = parse_ini_file(dirname(__FILE__)."/../config/config.ini",true); | |
} | |
/** | |
* return the key based on $group and $key identifiers. | |
* @param $group | |
* @param $key | |
*/ | |
public function get($group,$key, $default=""){ | |
if(isset(self::$_parameters[$group])&&isset(self::$_parameters[$group][$key])){ | |
return self::$_parameters[$group][$key]; | |
} else if($default==""){ | |
return "no exists"; | |
} else { | |
return $default; | |
} | |
} | |
/** | |
* Dynamic update for Config file, but this change didn't persist. | |
* @param unknown_type $group | |
* @param unknown_type $key | |
* @param unknown_type $value | |
*/ | |
public function set($group,$key,$value){ | |
self::$_parameters[$group][$key]=$value; | |
} | |
/** | |
* test if a flag is set into config.ini file. | |
* possible value for th flag are "on", "true" or "1". | |
* @see Debug::get($group,$key) | |
* @return true if flag is set, or false. | |
*/ | |
public function isActive($group,$key){ | |
$msg = $this->get($group,$key) ; | |
if( $msg == "on" || $msg=="true" || $msg=="1"){ | |
return true; | |
}else{ | |
return false; | |
} | |
} | |
/** | |
* initialise parmaters from config.ini file. | |
*/ | |
public function getInstance(){ | |
if(!isset(self::$_instance) || self::$_instance == null){ | |
self::$_instance = new Config(); | |
} | |
return self::$_instance; | |
} | |
} | |
/** | |
* helper to retreive quickly a config value. | |
*/ | |
function __config($group, $key,$default=""){ | |
return Config::getInstance()->get($group,$key); | |
} | |
/** | |
* helper to test a flag in the config file. | |
*/ | |
function __isActive($group, $key){ | |
return Config::getInstance()->isActive($group,$key); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment