1. Go to this page and download the library: Download camoo/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/ */
camoo / config example snippets
use Camoo\Config\Config;
use Camoo\Config\Enum\Parser;
// Load a single file
$conf = Config::load('config.json');
$conf = new Config('config.json');
// Load values from multiple files
$conf = new Config(['config.json', 'config.xml']);
// Load all supported files in a directory
$conf = new Config(__DIR__ . '/config');
// Load values from optional files
$conf = new Config(['config.dist.json', '?config.json']);
// Load a file using specified parser
$conf = new Config('configuration.config', Parser::JSON);
// Get value using key
$debug = $conf->get('debug');
// Get value using nested key
$secret = $conf->get('security.secret');
// Get a value with a fallback
$ttl = $conf->get('app.timeout', 3000);
// Get value using a simple key
$debug = $conf['debug'];
// Get value using a nested key
$secret = $conf['security.secret'];
// Get nested value like you would from a nested array
$secret = $conf['security']['secret'];
// Get all values
$data = $conf->all();
$conf = Config::load('config.json');
// Sample value from our config file
assert($conf['secret'] == '123');
// Update config value to something else
$conf['secret'] = '456';
// Reload the file
$conf = Config::load('config.json');
// Same value as before
assert($conf['secret'] == '123');
// This will fail
assert($conf['secret'] == '456');
use use Camoo\Config\Enum\Writer;
$config = Config::load('config.json');
$ini = $config->toString(Writer::INI); // Encode to string if you want to save the file yourself
$config->toFile('config.yaml');
$config->toFile('config.txt', Writer::SERIALIZE); // you can also force the writer