PHP code example of sheikhheera / iconfig

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

    

sheikhheera / iconfig example snippets


return array(
 	'default' => 'mysql',
	'connections' => array(
		'sqlite' => array(
			'driver'   => 'sqlite',
			'database' => 'public/caliber.sqlite',
			'prefix'   => 'cb_',
		),
		'mysql' => array(
			'driver'    => 'mysql',
			'host'      => 'localhost',
			'database'  => 'caliber',
			'username'  => 'root',
			'password'  => 'bossboss',
			'charset'   => 'utf8',
			'collation' => 'utf8_unicode_ci',
			'prefix'    => 'cb_',
		)
   ),
);

$config = new Iconfig\Config('config');

$default = $config->getDatabase('default'); // mysql

$settings = new Iconfig\Config('settings');

Array(
  'database' => array(
    'default' => 'mysql',
    'connections' => array(
		    'sqlite' => array(
			  'driver'   => 'sqlite',
			  'database' => 'public/caliber.sqlite',
			  'prefix'   => 'cb_',
		  )
  ),
  'session' => array(
    'driver' => 'native',
    'lifetime' 120,
    'files' => '/sessions'
  ),
  'chache' =>array(
    'path' => 'c:/web/app/storage'
  )
);

$settings->setDatabase('default', 'sqlite');
$settings->getDatabase('default'); // sqlite

$settings->setSession('lifetime', 240);
$settings->getSession('lifetime'); // 240

new Iconfig\Config('../myApp/config', 'Config'); // Config as Alias, you can use any name
if(Config::isExist('session')) {
    Config::setSession('driver', 'database');
    $sessionArray = Config::getSession(); // full array will be returned when called without argument
}

$chache = getChache('path', '/web') // if path doesn't exist then "/web" will be returned

Config::getDatabase('connections.sqlite.driver'); // get the driver from sqlite
Config::getDatabase('connections.pgsql.driver'); // get the driver from pgsql

$connections = Config::getDatabase('connections', function($data){
  if(is_array($data) && array_key_exists('sqlite', $data)) {
		Config::setDatabase('connections.sqlite.driver', 'myNewSqliteDriver');
		return Config::getDatabase('connections'); // this will return connections array with new value
	}
});

Config::find('sqlite'); // if it exists, you'll get the value
Config::find('connections.sqlite'); // it'll look sqlite in to the connections
Config::find('connections.sqlite.driver'); // it'll look driver in to the connections.sqlite array

$all = Config::getAll();
var_dump($all); // full configuration array will be returned

Config::load('filePath'); // new items will be added.