hierone / toml
A TOML parser and dumper for PHP that provides human-readable configuration with rigid structure
Installs: 5
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/hierone/toml
Requires
- php: >=8.2
- hierone/depreciation-contracts: ^1.0
Requires (Dev)
- phpunit/phpunit: ^10.4
This package is auto-updated.
Last update: 2025-10-09 05:48:52 UTC
README
A modern TOML parser and dumper for PHP 8.2+ that provides human-readable configuration with rigid structure.
Installation
composer require hierone/toml
Basic Usage
use Hierone\Component\Toml\Toml; // Parse TOML string $config = Toml::parse('title = "My App"'); // Convert array to TOML $toml = Toml::dump(['title' => 'My App']); // Load from file $config = Toml::parseFile('config.toml'); // Save to file Toml::dumpFile('config.toml', $config);
TOML Features
# Basic values title = "TOML Example" port = 8080 debug = true # Arrays ports = [8001, 8002, 8003] hosts = ["localhost", "127.0.0.1"] # Tables [database] host = "localhost" port = 5432 # Nested tables [database.connection] timeout = 30 pool_size = 10 # Array of tables [[servers]] name = "web1" ip = "192.168.1.1" [[servers]] name = "web2" ip = "192.168.1.2"
File Operations
use Hierone\Component\Toml\TomlFileLoader; $loader = new TomlFileLoader(); // Load multiple files $config = $loader->loadFiles(['base.toml', 'local.toml']); // Load directory $config = $loader->loadDirectory('/config'); // Validate file if ($loader->isValidTomlFile('config.toml')) { $config = $loader->loadFile('config.toml'); }
Error Handling
use Hierone\Component\Toml\Exception\ParseException; try { $config = Toml::parseFile('config.toml'); } catch (ParseException $e) { echo "Parse error: " . $e->getMessage(); }
Requirements
- PHP 8.2 or higher
- hierone/depreciation-contracts ^1.0
License
MIT License. See LICENSE for details.