PHP code example of stefna / config

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

    

stefna / config example snippets




// config.php

return [
	'config-key' => 'value',
	'nested' => [
		'key' => 'nested-value'
		'bool-key' => false,
	],
];

$config = new \Stefna\Config\FileConfig('path-to-php/config.php');
// config file is not read until it's needed

$config->getBool('nested.bool-key') === false;
$config->getString('config-key') === 'value';



// common.php

return [
	'config-key' => 'value',
	'nested' => [
		'key' => 'nested-value'
		'bool-key' => false,
	],
];



// production.php

return [
	'config-key' => 'production-value',
	'nested' => [
		'extra-key' => 42,
	],
];

$config = new \Stefna\Config\FileCollectionConfig('path-to-php/');
$config->addFile('common.php');
$config->addFile('production.php');

// config files is not read until it's needed

$config->getInt('nested.extra-key') === 42;
$config->getString('config-key') === 'product-value';

$rootConfig = new \Stefna\Config\FileCollectionConfig('path-to-php/');
$rootConfig->addFile('common.php');
$rootConfig->addFile('production.php');

$config = new \Stefna\Config\MutableConfig($rootConfig);

$config->setConfigValue('config-key', 'overridden-value');

$config->getString('config-key') === 'overridden-value';

$config->resetConfigValue('config-key');

$config->getString('config-key') === 'production-value';