PHP code example of nabeghe / configurator

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

    

nabeghe / configurator example snippets


use Nabeghe\Configurator\Configurator;
use Nabeghe\Configurator\Proxy;

class MyConfig extends Configurator
{
    const DEFAULTS = [
        'db' => [
            'type' => 'mysql',
            'host' => 'localhost',
            'port' => 3306,
        ],
        'debug' => [
            'enabled' => true,
        ],
    ];
}

$config = new MyConfig(path: __DIR__ . '/config');

// Accessing sections via Proxy
$db = $config->db;
echo $db->host; // localhost

// Using dot notation
$config->dot('db.host', '127.0.0.1');
echo $config->dot('db.host'); // 127.0.0.1

// Adding new keys or editing
$config->app->version = '1.0.0';

// Save a section
$config->db->save();

// Delete a key
$config->db->del('port');

// Iterate through keys
$config->database->each(function($key, $value) {
    echo "$key => $value\n";
});

// Get all configuration data including defaults
$allConfig = $config->getAll(addDefaults: true);