PHP code example of mcustiel / php-simple-config

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

    

mcustiel / php-simple-config example snippets


 
return array(
	'PRODUCTION' => array(
	    'DB' => array(
	        'user' => 'root',
	        'pass' => 'root',
	        'host' => 'localhost'
	    )
	),
	'STAGE' => array(
	    'DB' => array(
	        'user' => 'root',
	        'pass' => 'root',
	        'host' => 'localhost'
	    )
	),
	'LOCAL' => array(
	    'DB' => array(
	        'user' => 'root',
	        'pass' => 'root',
	        'host' => 'localhost'
	    )
	),
);

 
$config['PRODUCTION']['DB']['user'] = 'root';
$config['PRODUCTION']['DB']['pass'] = 'root';
$config['PRODUCTION']['DB']['host'] = 'localhost';
// ...
return $config;

$reader = new Mcustiel\Config\Drivers\Reader\php\Reader();
$reader->read(__DIR__ . "/resources/test.php");
$config = $reader->getConfig();

use Mcustiel\Config\Drivers\Reader\ini\Reader as IniReader;

$loader = new ConfigLoader("/test.ini", new IniReader());
$config = $loader->load();

$config->getFullConfigAsArray(); // This will return the full configuration as an array.
$config->get('PRODUCTION'); // Will return a $config object to access the subkeys defined under "PRODUCTION"
$config->get('PRODUCTION')->get('DB')->get('user'); // Will return 'root'

use Mcustiel\Config\Drivers\Reader\ini\Reader as IniReader;
use Mcustiel\Config\CacheConfig;

use Mcustiel\SimpleCache\Drivers\memcache\Cache;

$cacheManager = new Cache();
$cacheManager->init();

$loader = new ConfigLoader(
    "/test.ini",
    new IniReader(),
    new CacheConfig($cacheManager, 'test.ini.cache', 3600000)
);

// If the file is already cached, then next sentence loads it from cache; otherwise it's loaded
// from original config file and then saved in the cached version.
$config = $loader->load();

$writer = new Mcustiel\Config\Drivers\Writer\ini\Writer($iniConfig);
$writer->write(__DIR__ . "/resources/test-written.ini");