This class helps you load your application configs, it supports php, xml, ini and json files.
This class helps you load your application configs, it supports php, xml, ini, yml, neon and json files.
It's easy to use, and you can load multiple files with diferent formats at once
$ composer require masnathan/config4all
use MASNathan\Config\Config; $config = new Config(); //You can load as many files as you want, one by one $config->load('configs/config.php', 'configs/database.php'); //or all the files with a certain extension at the same time $config->load('configs/*.json'); //you can even load multiple format files at the same time $config->load('configs/*.json', 'configs/*.yml'); //or can also load multiple files, regardless of the extension $config->load('configs/*.*'); //This is how you clear all the configurations $config->clear();
//To get a value, you just need to know the path to get there //if you want to know my name, just use the get method and pass the configuration file name //and the keys to get my name, like this echo $config->get('config', 'me', 'name'); //here are some other examples echo $config->get('config', 'github'); echo $config->get('database', 'host'); //if the value that you are trying to get doesn't exist, you'll get a null //you can also get the entire structure by calling the method get with no arguments var_dump($config->get());
//You can also set new configs on the fly, or change existing ones $config ->set('a', 'b', 'c', 'value') ->set('config', 'me', 'name', 'Not Andre Filipe') ->set('database', 'host', 'first', 'localhost') ->set('database', 'host', 'second', 'somehost') ->set('this is a null field'); //This will return 'value' echo $config->set('a', 'b', 'c');
Please see CHANGELOG for more information what has changed recently.
$ composer test
Please see CONTRIBUTING for details.
If you discover any security related issues, please email email@example.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.