Configuration driver for CommonPHP that encodes and decodes INI configuration data.
- PHP
^8.5 comphp/config:^0.3
Once this package is available through your Composer repositories, install it with:
composer require comphp/config-ini<?php
use CommonPHP\Drivers\Config\INI\IniConfigurationDriver;
$driver = new IniConfigurationDriver();
$config = [
'app' => 'demo',
'debug' => true,
'database' => [
'host' => 'localhost',
],
];
$ini = $driver->encode($config);
$decoded = $driver->decode($ini);
$driver->write(__DIR__ . '/config.ini', $config);
$fromFile = $driver->read(__DIR__ . '/config.ini');This driver uses PHP's INI parser with typed scanning. Scalar values are supported at the top level, and one level of sections is supported for grouped values. Nested arrays beyond one section level are not supported by INI and are rejected during encoding.
Read, write, parse, validation, and unsupported value failures throw CommonPHP config exceptions such as ConfigReadException, ConfigWriteException, ConfigValidationException, or ConfigException.
MIT. See LICENSE.md.