PHP code example of raphhh / puppy-config

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

    

raphhh / puppy-config example snippets


// /config/global.php
return [
    'key' => 'value',
];

use Puppy\Config\Config;

$config = new Config();
$config['key']; //'value'

// /config/global.php
return [
    'key1' => 'value1',
    'key2' => '%key1%_b',
];

use Puppy\Config\Config;

$config = new Config();
$config['key2']; //'value1_b'

use Puppy\Config\Config;

$config = new Config();
$config['new_key'] = 'new_value';

$config['new_key2'] = '%new_key%';
$config['new_key2']; //'new_value'

//namespace a
$globalConfig['a.a'] = 'a.a';
$globalConfig['a.b'] = 'a.b';

//namespace b
$globalConfig['b.a'] = 'b.a';
$globalConfig['b.b'] = 'b.b';

$globalConfig['a.a']; //'a.a'
$globalConfig['b.a']; //'b.a'

$restrictedConfig = $globalConfig->restrict('a');

$restrictedConfig['a']; //'a.a'
$restrictedConfig['b']; //'a.b'

isset($restrictedConfig['a.a']); //false
isset($restrictedConfig['b.a']); //false

$restrictedConfig['a'] = 'new value';
$globalConfig['a.a']; //'new value'

// /config/global.php
return [
    'key' => 'value',
];

new Config('', null, new YmlFileReader()); //will load config/global.yml

new Config('dev'); //will load dev.php (in addition to global.php)

new Config(getenv('APP_ENV')); //will load dev.php only in your dev server