Wallogit.com
2017 © Pedro Peláez
Powerful tool for configurations
This is powerful configuration tool to manage every configuration file., (*1)
ini,php,json, (*2)
The preferred way to install this tool is through composer., (*3)
Either run, (*4)
php composer.phar require stdakov/config:dev-master
or add, (*5)
"stdakov/config": "dev-master"
For example we will have 3 configuration files in config dir: 'ini.ini' 'php.php' 'json.json', (*6)
require 'vendor/autoload.php'; $configFolder = 'config'; $helpersFolder = 'helpers'; $config = new \Dakov\Config();
We can also load helper functions if we have., (*7)
$config->loadHelpers($helpersFolder);
Lets load our configurations, (*8)
$config->loadConfigs($configFolder); print_r($config->listConfigs()); //This is file configuration names which are loaded
Output, (*9)
Array
(
[0] => ini
[1] => json
[2] => php
)
------------------INI--Configuration-----------------------, (*10)
print_r($config->load('ini')->get()->value()); print_r($config->load('ini')->get('database')->value()); try { print_r($config->load('ini')->get('server')->value()); } catch (\Exception $e) { var_dump($e->getMessage()); } try { print_r($config->load('app')->get('server')->value()); } catch (\Exception $e) { var_dump($e->getMessage()); } $config->load('ini')->get('database')->value()['DB_HOST'] == $config->load('ini')->get('database')->get('DB_HOST')->value();
Will output, (*11)
Array
(
[database] => Array
(
[DB_HOST] => localhost
[DB_DATABASE] => test
[DB_USERNAME] => root
[DB_PASSWORD] => test
)
[admin authentication] => Array
(
[ADMIN_AUTH] => 1
[ADMIN_TABLE] => admin
)
[upload] => Array
(
[tmp_dir] => /tmp
[upload_dir] => /public/storage
)
)
Array
(
[DB_HOST] => localhost
[DB_DATABASE] => test
[DB_USERNAME] => root
[DB_PASSWORD] => test
)
string(21) "Missing option:server"
string(25) "Missing Configuration:app"
------------------JSON--Configuration-----------------------, (*12)
print_r($config->load('json')->get()->value());
print_r($config->load('json')->get('name')->value());
Will output, (*13)
Array
(
[name] => stuff
[components] => Array
(
[Version] => Array
(
[versions] => 1
)
[Source] => Array
(
[ip] => 0.0.0.1
)
[Empty] => Array
(
)
)
)
stuff
------------------PHP--Configuration-----------------------, (*14)
print_r($config->load('php')->get()->value());
print_r($config->load('php')->get('test')->value());
Will output, (*15)
Array
(
[test] => Array
(
[show] => this is test
)
)
Array
(
[show] => this is test
)
------------------Custom Configuration-------------------------, (*16)
$configData = [
'user' => 'username',
'password' => 'password'
];
$config->set($configData, 'custom');
print_r($config->load('custom')->get()->value());
print_r($config->load('custom')->get('user')->value());
Will output, (*17)
Array
(
[user] => username
[password] => password
)
username
-------------------------------------------
-------------------Custom dir-INI-----------------------, (*18)
$customConfigPath = 'config/new/ini2.ini'; $config->registerConfig($customConfigPath); print_r($config->load('ini2')->get()->value()); print_r($config->load('ini2')->get('database')->value());
Will output, (*19)
Array
(
[database] => Array
(
[DB_HOST] => localhost
[DB_DATABASE] => test
[DB_USERNAME] => root
[DB_PASSWORD] => test
)
[admin authentication] => Array
(
[ADMIN_AUTH] => 1
[ADMIN_TABLE] => admin
)
[upload] => Array
(
[tmp_dir] => /tmp
[upload_dir] => /public/storage
)
)
Array
(
[DB_HOST] => localhost
[DB_DATABASE] => test
[DB_USERNAME] => root
[DB_PASSWORD] => test
)
string(21) "Missing option:server"
string(26) "Missing Configuration:app2"
-------------------Custom dir-INI-with custom name----------------------, (*20)
$customConfigPath = 'config/new/ini2.ini';
$config->registerConfig($customConfigPath, 'myIni');
print_r($config->load('myIni')->get()->value());
print_r($config->load('myIni')->get('database')->value());
Will output, (*21)
Array
(
[database] => Array
(
[DB_HOST] => localhost
[DB_DATABASE] => test
[DB_USERNAME] => root
[DB_PASSWORD] => test
)
[admin authentication] => Array
(
[ADMIN_AUTH] => 1
[ADMIN_TABLE] => admin
)
[upload] => Array
(
[tmp_dir] => /tmp
[upload_dir] => /public/storage
)
)
Array
(
[DB_HOST] => localhost
[DB_DATABASE] => test
[DB_USERNAME] => root
[DB_PASSWORD] => test
)
string(21) "Missing option:server"
string(21) "Missing option:server"
For working examples see the tests/example.php, (*22)
1.Implement xml files 2.Add functionality $config->load('ini2')->get('database.host')->value();, (*23)