PHP code example of jaxwilko / simple-config

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

    

jaxwilko / simple-config example snippets




use SimpleConfig\Compiler;
use SimpleConfig\Section;

$compiler = new Compiler();
$section = new Section();
$section->title = 'Database';
$section->key = 'database';
$section->comment = 'This is where your database config goes.';
$section->value = ['mysql' => ['host' => 'localhost']];
$compiler->addSection($section);
echo $compiler->render();



return [
    /*
    |----------------------------------------
    | Database
    |----------------------------------------
    | This is where your database config goes.
    |
    */

    'database' => [
        'mysql' => [
            'host' => 'localhost',
        ],
    ],
];



$compiler = new Compiler();
$compiler->addSection(new Section([
    'title'     => 'Database',
    'key'       => 'database',
    'comment'   => 'This is where your database config goes.',
    'value'     => ['mysql' => ['host' => 'localhost']],
]));
echo $compiler->render();

$compiler = new Compiler();
$compiler->addSection(new Section([
    'title' => 'Database',
    'comment' => 'This is where your database config goes.',
]));
echo $compiler->render();



return [
    /*
    |----------------------------------------
    | Database
    |----------------------------------------
    | This is where your database config goes.
    |
    */

];



$compiler = new Compiler();
$compiler->addSection(new Section([
    'key' => 'database',
    'value' => ['mysql' => ['host' => 'localhost']],
]));
echo $compiler->render();



return [
    'database' => [
        'mysql' => [
            'host' => 'localhost',
        ],
    ],
];



$compiler->addSection(new Section([
        'title' => 'Section one',
        'key' => 'section_one',
        'comment' => 'This is a section',
        'value' => [
            'foo' => 'bar',
            'bar' => [
                'foo'
            ]
        ]
    ]))
    ->addSection(new Section([
        'title' => 'Section two',
        'key' => 'section_two',
        'comment' => 'This is another section',
        'value' => [
            'bar' => 'foo',
            'foo' => [
                'bar'
            ]
        ]
    ]));



$compiler->addSection(new Section([
    'title' => 'Section',
    'key' => 'section',
    'comment' => 'This is a section',
    'value' => [
        'foo' => '@@env(\'VALUE\')',
    ]
]));



return [
    /*
    |----------------------------------------
    | Section
    |----------------------------------------
    | This is a section
    |
    */

    'section' => [
        'foo' => env('VALUE'),
    ],
];



// define the comment length
$compiler->option('length', 80);
// use spaces over tabs
$compiler->option('tabs', false);
// define the indentation length
$compiler->option('indent', 4);