PHP code example of jamesgober / config

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

    

jamesgober / config example snippets


use JG\Config\Config;

$config = new Config('/path/to/config/files');

// Load files
$config->load('database.json');
$config->load('app.xml');

// Access values
$dbHost = $config->get('database.host', 'default_host');

// Check keys
if ($config->has('app.debug')) {
    echo "Debug mode is enabled!";
}

// Add or update values
$config->add('app.name', 'MyApp');

// Delete specific values
$config->delete('app.version'); // Removes app.version

// Delete groups
$config->delete('app'); // Removes app.name, app.debug, etc.

use JG\Config\ConfigParserFactory;

// Register a parser for .custom files
ConfigParserFactory::registerParser('custom', MyCustomParser::class);

use JG\Config\Exceptions\ConfigException;

try {
    $config->load('missing_file.json');
} catch (ConfigException $e) {
    echo "Error: " . $e->getMessage();
}

src/
├── Config.php                  # Core configuration management class
├── ConfigParserFactory.php     # Factory for parser resolution
├── Exceptions/                 # Custom exceptions for robust error handling
│   ├── ConfigException.php
│   ├── ConfigParseException.php
│   └── InvalidParserException.php
├── Parsers/                    # Built-in parsers for supported formats
│   ├── ParserInterface.php
│   ├── PhpParser.php
│   ├── JsonParser.php
│   ├── IniParser.php
│   ├── XmlParser.php
│   └── YamlParser.php
tests/                          # Unit and integration tests