vaibhavpandeyvpz/kunfig
Helper library to easily merge & use multiple configuration files., (*1)
![Code Coverage][code-coverage-image]
![Latest Version][latest-version-image]
![Downloads][downloads-image]
![PHP Version][php-version-image]
![License][license-image], (*2)
, (*3)
Install
composer require vaibhavpandeyvpz/kunfig
Usage
<?php
/**
* @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
);
License
See LICENSE.md file., (*4)