Skip to content

Latest commit

 

History

History
34 lines (23 loc) · 814 Bytes

File metadata and controls

34 lines (23 loc) · 814 Bytes

Usage

comphp/config-ini provides CommonPHP\Drivers\Config\INI\IniConfigurationDriver for INI configuration files.

Encode and Decode

use CommonPHP\Drivers\Config\INI\IniConfigurationDriver;

$driver = new IniConfigurationDriver();

$config = [
    'name' => 'demo',
    'database' => [
        'host' => 'localhost',
    ],
];

$data = $driver->encode($config);
$decoded = $driver->decode($data);

Read and Write

$driver->write(__DIR__ . '/config.ini', $config);
$config = $driver->read(__DIR__ . '/config.ini');

Notes

The driver supports scalar top-level values and one level of INI sections. Deeper nested arrays are rejected during encoding. Typed values are parsed through INI_SCANNER_TYPED.

Failures throw CommonPHP config exceptions instead of returning false.