PHP code example of chilimatic / config-component

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

    

chilimatic / config-component example snippets


$config = new File(
    [
        \chilimatic\lib\Config\Adapter\File::CONFIG_PATH_INDEX  => __DIR__ . '/test/data',
        \chilimatic\lib\Config\Adapter\File::HOST_ID_KEY        => 'www.example.com' 
    ]
);

[ 
    '*.cfg', 
    '*.example.com.cfg', 
    'www.example.com.cfg'
]

[ 
    'all.cfg', 
    'all.example.com.cfg', 
    'www.example.com.cfg'
]

$config = new File(
    [
        \chilimatic\lib\Config\Adapter\File::CONFIG_PATH_INDEX  => __DIR__ . '/test/data',
        \chilimatic\lib\Config\Adapter\File::HOST_ID_KEY        => 'www.example.com' 
    ]
);
$config->set('key1', ['some', 'data']);
$config->set('key1', implode(' ', $config->get('key1')));

echo $config->get('key1'); // will return 'some data'

\chilimatic\lib\Config\ConfigFactory::make(
    'file',
     [
             \chilimatic\lib\Config\Adapter\File::CONFIG_PATH_INDEX  => __DIR__ . '/test/data',
             \chilimatic\lib\Config\Adapter\File::HOST_ID_KEY        => 'www.example.com' 
     ]
 ); // returns the same as the example above

// passed reference
$config = \chilimatic\lib\Config\Config::getInstance(
    'file',
     [
             \chilimatic\lib\Config\Adapter\File::CONFIG_PATH_INDEX  => __DIR__ . '/test/data',
             \chilimatic\lib\Config\Adapter\File::HOST_ID_KEY        => 'www.example.com' 
     ]
 );
// also accessable via
Config::set('my variable', 'my value);
Config::get('my variable');

$config = new \chilimatic\lib\Config\Adapter\Ini(
    [
         \chilimatic\lib\Config\Adapter\Ini::FILE_INDEX => __DIR__ . '/test/data/'
    ]
);
bash 
php myscript.php host=www.example.com
.ini