PHP code example of iviphp / config
1. Go to this page and download the library: Download iviphp/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/ */
iviphp / config example snippets
database.host
database.port
database.connections.mysql
declare(strict_types=1);
use Ivi\Config\Config;
$config = Config::load(__DIR__ . '/config');
declare(strict_types=1);
return [
'name' => 'My Application',
'environment' => 'production',
'debug' => false,
];
$appName = $config->get('app.name');
$debug = $config->get('app.debug', false);
declare(strict_types=1);
use Ivi\Config\Config;
$config = Config::fromArray([
'app' => [
'name' => 'My Application',
'debug' => true,
],
]);
$name = $config->get('app.name');
$host = $config->get(
'database.host',
'127.0.0.1'
);
$port = $config->get('database.port', 3306);
$items = $config->all();
if ($config->has('database.host')) {
// The configuration key exists.
}
$config->set('app.debug', true);
$config->set(
'database.connections.mysql.host',
'127.0.0.1'
);
$config->forget('app.debug');
$config->merge([
'database' => [
'port' => 3307,
'charset' => 'utf8mb4',
],
]);
$config->replace([
'app' => [
'name' => 'New Application',
],
]);
Config::load($directory);
Config::fromArray($items);
$config->get($key, $default);
$config->has($key);
$config->set($key, $value);
$config->forget($key);
$config->merge($items);
$config->replace($items);
$config->all();
text
config/
├── app.php
├── cache.php
└── database.php