PHP code example of cklamm / config
1. Go to this page and download the library: Download cklamm/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/ */
cklamm / config example snippets
// config.php
return [
'foo' => 'bar',
'array' => ['a', 'b', 'c'],
'db.driver' => 'mysql',
'db.host' => 'localhost',
'db.port' => 3306,
'log.debug.db' => '*',
'log.debug.file' => '*',
'log.prod.db' => 'error,warning,info',
'log.prod.file' => 'error,warning,info',
];
use cklamm\Config\ConfigFile;
$config = new ConfigFile('config.php');
$config->get('foo'); // 'bar'
$config->get('array'); // ['a', 'b', 'c']
$config->get('undefined'); // null
$config->get('db.driver'); // 'mysql'
$config->get('log.prod.db'); // 'error,warning,info'
$config->get('*'); // all entries
$config->get('db.*'); // all entries whose key starts with db.
$config->get('log.prod.*'); // all entries whose key starts with log.prod.
// config/db.php
return [
'driver' => 'mysql',
'host' => 'localhost',
'port' => 3306,
];
// config/log.php
return [
'debug.db' => '*',
'debug.file' => '*',
'prod.db' => 'error,warning,info',
'prod.file' => 'error,warning,info',
];
use cklamm\Config\ConfigFolder;
$config = new ConfigFolder('config');
$config->get('db.driver'); // 'mysql'
$config->get('log.prod.db'); // 'error,warning,info'
$config->get('*'); // null
$config->get('db'); // null
$config->get('db.*'); // all entries from config/db.php
$config->get('log.prod.*'); // all entries from config/log.php
// whose key starts with prod.