PHP code example of carstenwindler / config

1. Go to this page and download the library: Download carstenwindler/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/ */

    

carstenwindler / config example snippets




return [
    'my_config' => [
        'key1' => 'value1',
        'key2' => 'value2',
    ]
];


// load config from file with full path
$config = (new Config)->addConfigFile('/app/root/config/main_config.php');

// set the folder /app/root/config as your configuration folder
$config = (new Config)->setConfigPath('/app/root/config');
// load config from file /app/root/config/main_config.php
$config->addConfigFile('main_config.php');
// additionally, merge the config from /app/root/config/environment/develop.php
$config->addConfigFile('environment/develop.php');

$myConfiguration = [
	'key' => 'value'
];

$config = (new Config)->addConfigArray($myConfiguration);

$myOtherConfiguration = [
	'key2' => 'value2'
];

$config->mergeConfig($myOtherConfiguration);

$config = (new Config)->set('my.config.value.one', 12345);

$myConfiguration = [
    'lvl1' => [
        'test' => 'value',
        'lvl2' => [
            'foo' => 'wrong',
            'lvl3' => [
                'foo' => 'baz',
            ]
        ],
    ],
];

$config = (new Config)->setConfigArray($myConfiguration);

echo $config->get('lvl1.lvl2.lvl3.foo'); // echoes "baz"
echo $config->set('lvl1.lvl2.foo', 'bar');
echo $config->get('lvl1.lvl2.foo'); // echoes "bar"

echo $config->get('lvl1.lvl2.lvl3.nope', 'foo'); // echoes "foo"

is_null($config->get('lvl1.lvl2.lvl3.nope')); // true

main.php
\- environment/develop.php
 \- markets/my_market.php