PHP code example of openlss / lib-config

1. Go to this page and download the library: Download openlss/lib-config library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

openlss / lib-config example snippets



//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

//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);

self::_get()->config = array_merge($config,self::_get()->config);

//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'