PHP code example of kynetcode / wpzylos-config

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

    

kynetcode / wpzylos-config example snippets


use WPZylos\Framework\Config\ConfigRepository;

$config = new ConfigRepository([
    'app' => [
        'name' => 'My Plugin',
        'debug' => true,
    ],
    'database' => [
        'prefix' => 'myplugin_',
    ],
]);

// Dot-notation access
$config->get('app.name');           // 'My Plugin'
$config->get('app.debug');          // true
$config->get('missing', 'default'); // 'default'

// Typed accessors
$config->string('app.name');        // 'My Plugin'
$config->bool('app.debug');         // true
$config->int('database.port', 3306); // 3306

$config->get('database.connections.mysql.host');
$config->set('database.connections.mysql.port', 3307);
$config->has('database.connections.mysql'); // true

$config->string('app.name');            // Returns string, casts if needed
$config->int('database.port', 3306);    // Returns int
$config->float('rate.tax', 0.15);       // Returns float
$config->bool('app.debug');             // Handles 'true', '1', 'yes', 'on'
$config->array('app.providers', []);    // Returns array or default

$config = new ConfigRepository();
$config->loadDirectory(__DIR__ . '/config');

// Each PHP file becomes a top-level key:
// config/app.php    → $config->get('app.key')
// config/database.php → $config->get('database.key')

use WPZylos\Framework\Config\EnvLoader;

$env = new EnvLoader();
$env->load(__DIR__ . '/.env');

// Instance methods
$env->get('APP_DEBUG');     // Value from .env
$env->has('DB_HOST');       // true/false
$env->all();                // All parsed values

// Static helper (checks $_ENV, then getenv())
EnvLoader::env('APP_DEBUG', false);

$config->merge([
    'app' => ['version' => '2.0'],
]);
// Existing app values preserved, 'version' added