PHP code example of vaibhavpandeyvpz / kunfig

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

    

vaibhavpandeyvpz / kunfig example snippets




/**
 * @desc Create a Kunfig\Config instance with some initial values
 *      passed into constructor.
 */
$config = new Kunfig\Config(array(
    'database' => array(
        'host' => 'localhost',
        'port' => 3306,
        'charset' => 'utf8mb4',
    ),
    'debug' => false,
));

// Get a value
$host = $config->database->host;

// Set a value
$config->database->host = 'xxxxxxxxxxxxx.xxxxxxxxxxxxx.us-west-2.rds.amazonaws.com';

$override = new Kunfig\Config(array(
    'database' => array(
        'name' => 'test',
        'user' => 'root',
        'password' => null,
    ),
));

/**
 * @desc You can mix two Kunfig\ConfigInterface; the latter one
 *      will override values in the original one.
 */
$config->mix($override);

$pdo = new PDO(
    "mysql:host={$config->database->host}:{$config->database->port};dbname={$config->database->name}",
    $config->database->user,
    $config->database->password
);