Configuration access helper and environment manager
//build config
$config = array();
$config['test1'] = 'test';
$config['test2']['sec'] = 'test';
$config['test3']['sec'] = 'test2';
//load config
Config::setConfig($config); unset($config);
//set an additional
Config::set('test2.newsec',null,'testvalue');
//get options
$test = Config::get('test1');
$test2 = Config::get('test2.sec');
$test3 = Config::get('test2.newsec');
//get merged
$db = Config::getMerged('sec'); //will return test2
Config operates with an internal singleton even though all the methods are static.
To retrieve the singleton use the following
//use the clone keyword to actually copy the object (this is optional)
$inst = clone Config::_get();
//load up a new temporary config
Config::setConfig($newconfig);
//restore the old config
Config::$inst = clone $inst; unset($inst);
Returns the current singleton (will create one if it doesnt exist)
Will set the passed array to the main config This will merge with the existing config
Resets the internal config registry
var_dumps the internal config Note: use output buffers to capture this
Made to be used by packages will set the passed config below the internal config Example:
self::_get()->config = array_merge($config,self::_get()->config);
This allows userspace overrides to remain in affect regardless of registration time.
Sets a value in the config
Check if a value exists
Get a value from the confi structure
Get a merged value from the config tree Consider the following config structure
//full tree
$config['db']['driver'] = 'mysql';
$config['admin']['db']['driver'] = 'sqlite3';
Config::setConfig($config);
$val = Config::getMerged('admin','db.driver'); //returns 'sqllite'
//shorthand tree
$config['db']['driver'] = 'mysql';
Config::setConfig($config);
$val = Config::getMerged('admin','db.driver'); //returns 'mysql'
The idea is to retrieve a section from a subroot and gracefully look upstream.
Language | php |
Version | 0.0.0 |
Git URL | https://github.com/nullivex/lib-config |
License | GPL-3.0 |
Description | Configuration access helper and environment manager |
Keywords |