<?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);