1. Go to this page and download the library: Download phossa2/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/ */
phossa2 / config example snippets
use Phossa2\Config\Config;
use Phossa2\Env\Environment;
use Phossa2\Config\Loader\ConfigFileLoader;
// load environment from '.env' file
(new Environment())->load(__DIR__ . '/.env');
// create config instance with the config file loader
$config = new Config(
new ConfigFileLoader(
getenv('CONFIG_DIR'),
getenv('APP_ENV')
)
);
// object access of $config
$db_config = $config->get('db');
// array access of $config
$config['db.user'] = 'www';
$config1 = new Config();
$config2 = new Config();
$delegator = new Delegator();
// add some values
$config1['db.user'] = '${system.user}';
$config2['system.user'] = 'root';
// reference unresolved in $config1
var_dump($config1['db.user'] === '${system.user}'); // true
// add both configs to the delegator
$delegator->addConfig($config1);
$delegator->addConfig($config2);
// reference resolved thru the delegator
var_dump($config1['db.user'] === 'root'); // true
$dbUser = $delegator['db.user'];
// configs
$config1 = new Config();
$config2 = new Config();
// delegators
$delegator1 = new Delegator();
$delegator2 = new Delegator();
// register $config1 with $delegator1
$delegator1->addConfig($config1);
// chaining
$delegator2->addConfig($delegator1);
$delegator2->addConfig($config2);
// get from the chain
$db = $delegator2->get('db');
// disable writing to the $config
$config->setWritable(false);