PHP code example of dikki / config

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

    

dikki / config example snippets


use Dikki\Config\ConfigFetcher;

$configFetcher = new ConfigFetcher(__DIR__ . '/config');

// Fetch all configurations
$config = $configFetcher->fetch();

// Get a specific configuration value using dot notation
echo $configFetcher->get('app.timezone');

use Dikki\Config\Config;
use Dikki\Config\YamlParser;

// Create an instance of the Config class
$config = new Config(new YamlParser(__DIR__ . '/config')); # pass either single file path or whole directory

// Get a configuration value (dot notation is supported)
echo $config->get('app.timezone');

public function __construct(string $path)

public function __construct(ConfigInterface $parser)

use Dikki\Config\Config;
use Dikki\Config\ConfigFetcher;
use Dikki\Config\DotEnvParser;
use Dikki\Config\IniParser;
use Dikki\Config\JsonParser;
use Dikki\Config\NeonParser;
use Dikki\Config\PhpArrayParser;
use Dikki\Config\YamlParser;
use Tester\Assert;

sonConfig = new Config(new JsonParser($configDir . '/jsonconfig.json'));
$neonConfig = new Config(new NeonParser($configDir . '/neonconfig.neon'));
$phpConfig = new Config(new PhpArrayParser($configDir . '/phpconfig.php'));
$yamlConfig = new Config(new YamlParser($configDir . '/yamlconfig.yaml'));

// Test individual parsers
Assert::equal($dotenvConfig->get('APP_NAME'), "Sample App");
Assert::equal($iniConfig->get('app.url'), "https://example.com");
Assert::equal($jsonConfig->get('app.author'), "Naman");
Assert::equal($neonConfig->get('app.debug'), false);
Assert::equal($phpConfig->get('app.timezone'), "Asia/Kolkata");
Assert::equal($yamlConfig->get('app.theme'), "Default");

// Test ConfigFetcher
Assert::equal($configFetcher->get('APP_NAME'), "Sample App");
Assert::equal($configFetcher->get('app.author'), "Naman");
Assert::equal($configFetcher->get('app.url'), "https://example.com");
Assert::equal($configFetcher->get('app.debug'), false);
Assert::equal($configFetcher->get('app.timezone'), "Asia/Kolkata");
Assert::equal($configFetcher->get('app.theme'), "Default");