1. Go to this page and download the library: Download rnr1721/le7-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/ */
rnr1721 / le7-config example snippets
use Core\Config\ConfigFactoryGeneric;
$data = [
'myparam' => 2,
'myparam2' => "string value",
'myparam3' => [
'myparam4' => false,
'myparam5' => 44.33
]
];
$factory = new ConfigFactoryGeneric();
$config = $factory->fromArray($data);
// Get params as object properties (null if empty)
echo $config->myparam;
echo $config->myparam3->myparam5;
// Get params as array
echo $config['myparam'];
echo $config['myparam3']['myparam5'];
// Get params by path (recommended way)
echo $config->int('myparam',54); // 54 is default value if not exists in config
echo $config->float('myparam3.myparam5',33.44); // 33.44 is default value if not exists in config
echo $config->float('myparam3.myparam5'); // throw exception if value not exists in config
var_dump($config->bool('myparam4/myparam4',true,'/'));
echo $config->string('myparam2',"default value");
use Core\Config\ConfigFactoryGeneric;
$filename = '/var/www/example.com/htdocs/config/config.php';
$factory = new ConfigFactoryGeneric();
$config = $factory->fromJsonFile($filename, 'My JSON config');
// echo $config['myparam']...
use Core\Config\ConfigFactoryGeneric;
$folders = [
'/var/www/example.com/htdocs/config',
'/var/www/example.com/htdocs/config2'
];
$factory = new ConfigFactoryGeneric();
// $folders can be string - one folder or array
// seconf parameter - is suffix between filename and extension i.e. dbConfig.ini or dbConfig.php in this case
$config = $factory->harvest($folders, 'Config');
// $config->string('myparam')
use Core\Config\ConfigFactoryGeneric;
$filename = '/var/www/example.com/htdocs/config/config.php';
// $cache is PSR Cacheinterface
$factory = new ConfigFactoryGeneric($cache);
// myconfig is cache key to store in cache
$config = $factory->fromArrayFile($filename, 'My PHP config', 'myconfig');
// $config->string('myparam')
use Core\Config\ConfigFactoryGeneric;
$data = [
'myparam' => 2,
'myparam2' => "My site is {myvariable1}",
'myparam3' => [
'myparam4' => false,
'myparam5' => 44.33
]
];
$factory = new ConfigFactoryGeneric();
$config = $factory->fromArray($data);
$config->applyFilter('vyvariable1','https://example.com');
// stringf will return "My site is https://example.com"
echo $config->stringf('myparam2');
use Core\Config\ConfigFactoryGeneric;
$data = [
'myparam' => 2,
'myparam2' => "My site is {myvariable1}",
'myparam3' => [
'myparam4' => false,
'myparam5' => 44.33
]
];
$factory = new ConfigFactoryGeneric();
$config = $factory->fromArray($data);
// Add own parameter
$config->registerParam('myparam3.testparam77',"test value");
// Get this parameter
$config->string("myparam3.testparam77");
use Core\Config\ConfigFactoryGeneric;
$data = [
'myparam' => 2,
'myparam2' => "My site is {myvariable1}",
'myparam3' => [
'myparam4' => false,
'myparam5' => 44.33
]
];
$factory = new ConfigFactoryGeneric();
$config = $factory->fromArray($data);
// Add own parameter 1
$config->registerParam('myparam3.testdirhome',"/home/www",'homepath');
// Add own parameter 2
$config->registerParam('myparam3.testdirbase',"{homepath}/base");
// Get this parameter (return /home/www/base)
$config->stringf("myparam3.testdirbase");
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.