PHP code example of microlib / config

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

    

microlib / config example snippets




use MicroLib\Config as cfg;

$config = cfg\load('config.json');

$schema = cfg\schema([
    'first_name' => [
        ' 'ctype_alpha'
    ],
    'last_name' => [
        ' 'ctype_alpha'
    ],
    'phone' => [
        'schema' => [
             'type' => [
                 'default'   => 'mobile',
                 'transform' => 'trim',
                 'validate'  => 'ctype_alpha',
             ],
             'number' => [
                 '

$config = cfg\validate($config, $schema);

echo cfg\get($config, 'phone.number');
#> 5559997777

echo cfg\get($config, 'phone.type');
#> mobile

$config = [
    'class'  => 'rogue',
    'race'   => 'half-elf',
    'level'  => 5,
    'weapon' => 'short sword',
];

$config = cfg\keep($config, ['class', 'race', 'level']);

$config = cfg\create(
	$config,
	['class', 'race', 'level'],
	['status' => 'normal']
);

print_r($config);
#> Array
#> (
#>     [class] => rogue
#>     [race] => half-elf
#>     [level] => 5
#>     [status] => normal
#> )