PHP code example of dvxgit-jalonzo / prototype-configuration

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

    

dvxgit-jalonzo / prototype-configuration example snippets


use Nrmnalonzo\Prototype\PrototypeConfiguration;

$config = new PrototypeConfiguration('app-settings.json');

// Get values
echo $config->get('app.name'); // "My Application"
echo $config->get('app.maintenance', false); // false (with default)

// Update values
$config->set('app.maintenance', true);
$config->set('features.newsletter', false);

$config = new PrototypeConfiguration('settings.json');

// Get all configuration as array
$all = $config->all();

// Get specific value with dot notation
$appName = $config->get('app.name');

// Get with default value if key doesn't exist
$debug = $config->get('app.debug', false);

// Get nested values
$emailHost = $config->get('mail.smtp.host');

// Set a single value
$config->set('app.name', 'Updated App Name');

// Set multiple values at once (more efficient)
$config->setMany([
    'app.name' => 'My App',
    'app.version' => '2.0.0',
    'features.new_feature' => true,
]);

// Replace entire configuration
$config->replace([
    'app' => [
        'name' => 'Brand New App',
        'version' => '1.0.0'
    ]
]);

// Remove a key (supports dot notation)
$config->forget('app.debug');
$config->forget('features.old_feature');

// Remove specific array item by index
$config->forgetArrayItem('users', 0); // removes first user

$features = new PrototypeConfiguration('features.json');

if ($features->get('dark_mode.enabled')) {
    // Enable dark mode UI
}

// Toggle feature
$features->set('maintenance_mode', true);

$settings = new PrototypeConfiguration('settings.json');

// Update multiple settings
$settings->setMany([
    'timezone' => 'Asia/Manila',
    'locale' => 'en',
    'per_page' => 25,
]);

$config = new PrototypeConfiguration('runtime.json');

// Track application state
$config->set('last_backup', now()->toDateTimeString());
$config->set('total_users', User::count());

try {
    $config = new PrototypeConfiguration('nonexistent.json');
} catch (RuntimeException $e) {
    // Handle missing file
}

  new PrototypeConfiguration('settings'); // Same as 'settings.json'