PHP code example of phppkg / config

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

    

phppkg / config example snippets


use PhpPkg\Config\ConfigBox;

$config = ConfigBox::new();
$config->loadFromFiles([
    __DIR__ . '/test/testdata/config.ini',
    __DIR__ . '/test/testdata/config.neon',
    __DIR__ . '/test/testdata/config.yml',
    __DIR__ . '/test/testdata/config.toml',
]);

use PhpPkg\Config\ConfigBox;

$config = ConfigBox::newFromFiles([
    // ... config file list
]);

$config->loadIniFile('path/to/my.ini')

// dump config
vdump($config->getData());

CALL ON PhpPkg\ConfigTest\ConfigBoxTest(24):
array(7) {
  ["name"]=> string(6) "inhere"
  ["age"]=> int(89)
  ["atIni"]=> string(6) "value0"
  ["arr0"]=> array(3) {
    [0]=> string(2) "ab"
    [1]=> int(23)
    [2]=> string(2) "de"
  }
  ["map0"]=> array(2) {
    ["key0"]=> string(4) "val0"
    ["key1"]=> string(4) "val1"
  }
  ["atNeon"]=> string(6) "value1"
  ["atYaml"]=> string(6) "value2"
  ["atToml"]=> string(6) "val at toml"
}

/** @var PhpPkg\Config\ConfigBox $config */
$config->getInt('age'); // int(89)
$config->getString('name'); // string('inhere')
$config->get('arr0');
$config->get('map0');

// get value by key-path.
$config->getInt('arr0.1'); // int(23)
$config->getString('map0.key0'); // string('val0')

/** @var PhpPkg\Config\ConfigBox $config */
$config->set('name', 'INHERE');
$config->set('map0.key0', 'new value');

// set multi at once
$config->sets([
    'key1' => 'value1',
    'key2' => 'value2',
    // ...
]);

use PhpPkg\Config\ConfigBox;

/** @var ConfigBox $config */
$config->exportTo('/path/to/file.json');
$config->exportTo('/path/to/my.conf', ConfigBox::FORMAT_YAML);