PHP code example of caiola / config

1. Go to this page and download the library: Download caiola/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/ */

    

caiola / config example snippets




// Autoload files using Composer autoload
$loader = )->setImmutable(false);
Config::getInstance()->setUseEnvironment(true);

echo "# windir: " . Config::getInstance()->windir . PHP_EOL;

Config::getInstance()->windir = 'c:\\win\\';

echo "# windir: " . Config::getInstance()->windir . PHP_EOL;



// Autoload files using Composer autoload
$loader = ironment variables
Config::getInstance()->setUseEnvironment(true);

// Allow to override environment variables
Config::getInstance()->setImmutable(true);

// Configuration example
$databases = array(
    'error_log' => '/var/log/error_log',
    'master'    => array(
        'host' => '127.0.0.1',
        'port' => '3306',
        'user' => 'root',
        'pass' => 'pass',
        'db'   => 'dbapp'
    )
);

Config::getInstance()->set($databases);

// Obtain configuration values through several methods
$cfg = new Config();
echo "# db master: " . $cfg->master['db'] . PHP_EOL;
echo "# db master: " . Config::getInstance()->master['db'] . PHP_EOL;
echo "# db master: " . Config::getByKey("master.db") . PHP_EOL;

echo "# error_log: " . $cfg->error_log . PHP_EOL;
echo "# error_log: " . Config::getInstance()->error_log . PHP_EOL;
echo "# error_log: " . Config::getByKey("error_log") . PHP_EOL;

echo "# windir: " . $cfg->windir . PHP_EOL;
echo "# windir: " . Config::getInstance()->windir . PHP_EOL;
echo "# windir: " . Config::getByKey("windir") . PHP_EOL;