Git Product home page Git Product logo

config-ini's Introduction

INI Configuration Driver for CommonPHP

This library introduces the INI configuration driver, IniConfigurationDriver, as part of the CommonPHP Configuration Management ecosystem. It extends the functionality of CommonPHP by allowing applications to seamlessly load and save configurations using INI files.

Features

  • Load INI Configurations: Simplifies the process of reading INI files and converting them into associative arrays for easy access within PHP applications.
  • Save Configurations as INI: Offers the ability to serialize PHP associative arrays back into INI format, preserving the structure and hierarchies.
  • Structured Error Handling: Incorporates detailed exception handling to manage potential parsing and file operation errors effectively.
  • Support for Nested Structures: Through a custom implementation, it supports the representation of nested structures within INI files, providing greater flexibility in configuration management.

Installation

Use Composer to integrate both the Configuration Manager and the INI driver into your project:

composer require comphp/config
composer require comphp/config-ini

Usage

To utilize the INI driver with the Configuration Manager, first ensure the DriverManager is configured to recognize the INI driver:

use CommonPHP\Drivers\DriverManager;
use CommonPHP\Configuration\Drivers\IniConfigurationDriver\IniConfigurationDriver;

$driverManager = new DriverManager();
$driverManager->enable(IniConfigurationDriver::class);

Upon configuration, the IniConfigurationDriver will be automatically used for .ini file extensions, thanks to the #[ConfigurationDriverAttribute('ini')] annotation.

Loading a Configuration File

$configManager->loadDriver(IniConfigurationDriver::class);
$config = $configManager->get('path/to/configuration.ini');

Saving a Configuration File

After loading the driver as described above, modifications can be saved back to the INI file:

$config->data['newSection'] = ['newKey' => 'newValue'];
$config->save(); // Persists the changes to 'path/to/configuration.ini'

Exception Handling

The driver includes specific exception handling for common issues such as:

  • ConfigurationException: Thrown for errors related to INI file parsing or when the file format does not meet the expected structure.
  • General Exceptions: For file read/write operations or parsing failures.

config-ini's People

Contributors

tlmcclatchey avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.