Matomo Ini
A PHP library to read and write INI configuration files with real typing and exceptions.
Repository Health
Technical Analysis
Matomo Ini is a PHP component for reading and writing INI configuration files that improves on PHP’s built-in parse_ini_file(). Where the native function only reads, returns weakly-typed strings, and emits PHP errors, Matomo Ini can also write INI files, parses booleans and numbers into real PHP types, and throws exceptions you can catch.
Because reading and writing are exposed as injectable classes rather than global functions, they can be passed as dependencies and mocked in unit tests, making configuration handling first-class and testable in modern application code.
What You Get
- An IniReader that parses INI files and strings into typed PHP arrays
- An IniWriter that serializes PHP arrays back into INI format
- Automatic parsing of boolean and numeric values into real PHP types
- Dedicated IniReadingException and IniWritingException for error handling
- Injectable, mockable classes instead of global functions
Common Use Cases
- Loading application configuration from INI files with correct types
- Programmatically writing or updating INI configuration files
- Validating configuration input and catching parse errors as exceptions
- Mocking configuration reads and writes in unit tests
Under The Hood
Architecture - The component is four classes in src/: IniReader and IniWriter provide the read/write surface, while IniReadingException and IniWritingException represent failure modes. IniReader normalises raw INI values into typed PHP scalars, and IniWriter performs the inverse, producing INI text from a PHP array. Because both are plain objects rather than static helpers, they slot cleanly into dependency-injection containers.
Tech Stack - Pure PHP (>=7.2) with PSR-4 autoloading under Matomo\Ini\ and no runtime dependencies. The project ships PHPUnit tests and a phpbench.json for benchmarking.
Code Quality - The code is compact, single-responsibility, and covered by a dedicated tests/ directory, with explicit exception types making error paths clear. It is a mature, stable component rather than one under active feature development.
API Design - The API is intuitive: instantiate a reader or writer and call a read/write method. Typed return values and thrown exceptions mean callers avoid the string-coercion and error-suppression pitfalls of parse_ini_file(), with almost no boilerplate.