PHP code example of improvframework / configuration
1. Go to this page and download the library: Download improvframework/configuration 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/ */
$config = new \Improv\Configuration($_ENV, 'APP_');
// Use the built-in boolean mapper
$config->map('DEBUG_ON')->toBool();
// Assign multiple keys at once, using built-in int mapper
$config->map('DEBUG_VERBOSITY', 'MAX_LOGIN_ATTEMPTS')->toInt();
// Invoke the "using" method to and callback to parse values
$config->map(
'WHITELIST_CIDR',
'DB_READ_POOL'
)->using(
function($val) {
return explode('|', $val);
}
);
// Now, all future retrievals from any part of the application
// will spit out the translated value(s)
// ... //
$config->get('DEBUG_ON'); // bool(false)
$config->get('DEBUG_VERBOSITY'); // int(4)
$config->get('MAX_LOGIN_ATTEMPTS'); // int(3)
$config->get('WHITELIST_CIDR');
// array(2) {
// [0] => string(14) "123.456.7.8/32"
// [1] => string(14) "123.456.255/12"
// }
class DelimiterMap
{
private $delimiter;
public function __construct($delimiter)
{
$this->delimiter = $delimiter;
}
public function __invoke($value)
{
return explode($this->delimiter, $value);
}
}
// ... //
$config->map('WHITELIST_CIDR')->using(new DelimiterMap('|'));
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.